| Total Complexity | 7 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class FirstSuccessfulEnvResolvingStrategy implements EnvResolvingStrategyInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array|EnvResolvingStrategyInterface[] $strategies |
||
| 11 | */ |
||
| 12 | private $strategies = []; |
||
| 13 | |||
| 14 | 6 | public function __construct(array $strategies = []) |
|
| 15 | { |
||
| 16 | 6 | $this->addStrategies($strategies); |
|
| 17 | 6 | } |
|
| 18 | |||
| 19 | 6 | public function getEnv(string $envName): string |
|
| 20 | { |
||
| 21 | 6 | foreach ($this->strategies as $strategy) { |
|
| 22 | 5 | $envValue = $strategy->getEnv($envName); |
|
| 23 | 5 | if ($envValue !== '') { |
|
| 24 | 5 | return $envValue; |
|
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | 1 | return ''; |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param array|EnvResolvingStrategyInterface[] $strategies |
||
| 33 | */ |
||
| 34 | 6 | private function addStrategies(array $strategies): void |
|
| 35 | { |
||
| 36 | 6 | foreach ($strategies as $strategy) { |
|
| 37 | 5 | $this->addStrategy($strategy); |
|
| 38 | } |
||
| 39 | 6 | } |
|
| 40 | |||
| 41 | 5 | private function addStrategy(EnvResolvingStrategyInterface $strategy): void |
|
| 44 | 5 | } |
|
| 45 | } |
||
| 46 |