ServerHeadersBasedHostDetector::getCurrentHost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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