EnvProviderDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A getEnv() 0 7 2
A resetStrategy() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\MultiEnv\Decorator;
6
7
use Lamoda\MultiEnv\Decorator\Exception\EnvProviderDecoratorException;
8
use Lamoda\MultiEnv\Strategy\EnvResolvingStrategyInterface;
9
10
final class EnvProviderDecorator
11
{
12
    /**
13
     * @var EnvResolvingStrategyInterface|null $resolvingStrategy
14
     */
15
    private static $resolvingStrategy;
16
17 1
    public static function init(EnvResolvingStrategyInterface $resolvingStrategy): void
18
    {
19 1
        self::$resolvingStrategy = $resolvingStrategy;
20 1
    }
21
22 2
    public static function resetStrategy(): void
23
    {
24 2
        self::$resolvingStrategy = null;
25 2
    }
26
27
    /**
28
     * @param string $envName
29
     * @throws EnvProviderDecoratorException
30
     * @return string
31
     */
32 2
    public static function getEnv(string $envName): string
33
    {
34 2
        if (self::$resolvingStrategy === null) {
35 1
            throw EnvProviderDecoratorException::becauseDecoratorNotInitialised();
36
        }
37
38 1
        return self::$resolvingStrategy->getEnv($envName);
39
    }
40
}
41