ServerHeadersBasedHostDetector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
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 27
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getCurrentHost() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\MultiEnv\HostDetector;
6
7
use Lamoda\MultiEnv\HostDetector\Exception\HostDetectorException;
8
use Lamoda\MultiEnv\Model\HostId;
9
10
final class ServerHeadersBasedHostDetector implements HostDetectorInterface
11
{
12
    /**
13
     * @var string $needle
14
     */
15
    private $needle;
16
17
    /**
18
     * @param string $needle
19
     * @throws HostDetectorException
20
     */
21 16
    public function __construct(string $needle)
22
    {
23 16
        $needle = trim($needle);
24
25 16
        if (empty($needle)) {
26 3
            throw HostDetectorException::becauseEmptyNeedlePassed(self::class);
27
        }
28
29 13
        $this->needle = $needle;
30 13
    }
31
32 31
    public function getCurrentHost(): HostId
33
    {
34 31
        $hostId = (string)($_SERVER[$this->needle] ?? '');
35
36 31
        return new HostId($hostId);
37
    }
38
}
39