Total Complexity | 7 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class FirstSuccessfulHostDetector implements HostDetectorInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var array|HostDetectorInterface[] $detectors |
||
13 | */ |
||
14 | private $detectors = []; |
||
15 | |||
16 | 13 | public function __construct(array $detectors = []) |
|
19 | 13 | } |
|
20 | |||
21 | 22 | public function getCurrentHost(): HostId |
|
22 | { |
||
23 | 22 | foreach ($this->detectors as $detector) { |
|
24 | 20 | $hostId = $detector->getCurrentHost(); |
|
25 | 20 | if ((string)$hostId !== '') { |
|
26 | 20 | return $hostId; |
|
27 | } |
||
28 | } |
||
29 | |||
30 | 3 | return new HostId(''); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param array|HostDetectorInterface[] $detectors |
||
35 | */ |
||
36 | 13 | private function addDetectors(array $detectors): void |
|
37 | { |
||
38 | 13 | foreach ($detectors as $detector) { |
|
39 | 12 | $this->addDetector($detector); |
|
40 | } |
||
41 | 13 | } |
|
42 | |||
43 | 12 | private function addDetector(HostDetectorInterface $detector): void |
|
46 | 12 | } |
|
47 | } |
||
48 |