EnvProviderDecorator::resetStrategy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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