HostBasedEnvResolvingStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEnv() 0 6 1
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