FileBasedEnvResolvingStrategy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\MultiEnv\Strategy;
6
7
use Lamoda\MultiEnv\FileReader\EnvFileReaderInterface;
8
use Lamoda\MultiEnv\HostDetector\HostDetectorInterface;
9
10
final class FileBasedEnvResolvingStrategy implements EnvResolvingStrategyInterface
11
{
12
    /**
13
     * @var HostDetectorInterface
14
     */
15
    private $hostDetector;
16
17
    /**
18
     * @var EnvFileReaderInterface
19
     */
20
    private $envFileReader;
21
22
    /**
23
     * @var EnvResolvingStrategyInterface
24
     */
25
    private $envResolvingStrategy;
26
27 8
    public function __construct(
28
        HostDetectorInterface $hostDetector,
29
        EnvFileReaderInterface $envFileReader,
30
        EnvResolvingStrategyInterface $envResolvingStrategy
31
    ) {
32 8
        $this->hostDetector = $hostDetector;
33 8
        $this->envFileReader = $envFileReader;
34 8
        $this->envResolvingStrategy = $envResolvingStrategy;
35 8
    }
36
37 8
    public function getEnv(string $envName): string
38
    {
39 8
        $hostId = $this->hostDetector->getCurrentHost();
40 8
        $this->envFileReader->readEnvFile($hostId);
41
42 8
        return $this->envResolvingStrategy->getEnv($envName);
43
    }
44
}
45