| Conditions | 5 |
| Paths | 3 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | 47 | public function resolve(string $key, ?string $value): ?string |
|
| 18 | { |
||
| 19 | 47 | if ($value === null) { |
|
| 20 | 4 | return null; |
|
| 21 | } |
||
| 22 | 46 | $result = preg_replace_callback( |
|
| 23 | '/(\${(?<variable>.+?)(?<default_value>:[-=?][^}]*)?})/', |
||
| 24 | 46 | function (array $matches): string { |
|
| 25 | 21 | $env = getenv($matches['variable']) ?: null; |
|
| 26 | |||
| 27 | /** @var string|bool|int|float|null $val */ |
||
| 28 | 19 | $val = |
|
| 29 | 21 | $env ?? |
|
| 30 | 19 | $this->dotenv->getEnvCollection()->get($matches['variable']) ?? |
|
| 31 | 13 | $this->dotenv->getEnvRawArray()[$matches['variable']] ?? |
|
| 32 | 7 | ($matches['default_value'] ? $this->resolveDefaultValue( |
|
| 33 | 6 | $matches['default_value'], |
|
| 34 | 6 | $matches['variable'] |
|
| 35 | 5 | ) : null) ?? |
|
| 36 | ''; |
||
| 37 | |||
| 38 | 19 | return Helper::scalarValueToString($val); |
|
| 39 | }, |
||
| 40 | $value, |
||
| 41 | flags: PREG_UNMATCHED_AS_NULL |
||
| 42 | ); |
||
| 43 | |||
| 44 | 45 | if (preg_match('/(\${(.+?)})/', $result)) { |
|
| 45 | 1 | return $this->resolve($key, $result); |
|
| 46 | } |
||
| 47 | |||
| 48 | 45 | return $result; |
|
| 49 | } |
||
| 68 |