HostBasedEnvResolvingStrategy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
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\Formatter\Exception\FormatterException;
8
use Lamoda\MultiEnv\Formatter\FormatterInterface;
9
use Lamoda\MultiEnv\HostDetector\HostDetectorInterface;
10
11
final class HostBasedEnvResolvingStrategy implements EnvResolvingStrategyInterface
12
{
13
    /**
14
     * @var HostDetectorInterface
15
     */
16
    private $hostDetector;
17
18
    /**
19
     * @var FormatterInterface $envNameFormatter
20
     */
21
    private $envNameFormatter;
22
23 15
    public function __construct(HostDetectorInterface $hostDetector, FormatterInterface $envNameFormatter)
24
    {
25 15
        $this->hostDetector = $hostDetector;
26 15
        $this->envNameFormatter = $envNameFormatter;
27 15
    }
28
29
    /**
30
     * @param string $envName
31
     * @throws FormatterException
32
     * @return string
33
     */
34 20
    public function getEnv(string $envName): string
35
    {
36 20
        $hostId = $this->hostDetector->getCurrentHost();
37 20
        $envName = $this->envNameFormatter->formatName($envName, $hostId);
38
39 19
        return (string)getenv($envName);
40
    }
41
}
42