Skip to content

Commit 4aacf1d

Browse files
committed
- fixes the wrong 'root' name
- do not reset the env() internal dataset if .env is not found - [CS] constructor property promotion
1 parent 93c67f3 commit 4aacf1d

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Config.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
*/
6666
class Config extends Arguments implements Configuration
6767
{
68-
public string $root = '';
6968
private bool $silent = false;
7069

7170
/**
@@ -76,12 +75,12 @@ class Config extends Arguments implements Configuration
7675
* this is the application's root path
7776
* @param Data|null $defaults [optional] An Optional config object with default values
7877
*/
79-
public function __construct(string $root = '', Data $defaults = null)
78+
public function __construct(
79+
public string $root = '',
80+
Data $defaults = null)
8081
{
81-
parent::__construct($defaults ? $defaults->toArray() : []);
82-
if (!$this->root = $root) {
83-
$this->root = getcwd();
84-
}
82+
parent::__construct($defaults?->toArray() ?? []);
83+
$this->root ??= getcwd();
8584
}
8685

8786
/**
@@ -118,7 +117,7 @@ public function fromObject(object|string $object): Configuration
118117
if (is_string($object) && class_exists($object)) {
119118
$object = new $object;
120119
}
121-
$this->root = $object->rootPath ?: $this->root;
120+
$this->root ??= $object->root;
122121
return $this->import(iterator_to_array($object));
123122
}
124123

@@ -143,7 +142,6 @@ public function fromEnvFile(string $filename, string $namespace = ''): Configura
143142
env('', null, $this->filter($data, $namespace, false));
144143
} catch (Exception $e) {
145144
error_log('[Configuration error]: ' . $e->getMessage());
146-
env('', null, []);
147145
} finally {
148146
return $this;
149147
}
@@ -196,8 +194,9 @@ public function namespace(
196194
bool $lowercase = true,
197195
bool $trim = true): static
198196
{
199-
return (new static($this->root))
200-
->import($this->filter($this->toArray(), $prefix, $lowercase, $trim));
197+
return (new static($this->root))->import(
198+
$this->filter($this->toArray(), $prefix, $lowercase, $trim)
199+
);
201200
}
202201

203202
protected function loadDataFrom(string $filename, callable $loader): Configuration

0 commit comments

Comments
 (0)