| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 9 | final class HostnameCollection implements IteratorAggregate, \Countable |
||
| 10 | { |
||
| 11 | private $hostnames; |
||
| 12 | |||
| 13 | public function __construct(Hostname ...$hostnames) |
||
| 14 | { |
||
| 15 | Assertion::greaterThan($hostnames, 0, "There is no hostname"); |
||
| 16 | $this->hostnames = $hostnames; |
||
| 17 | } |
||
| 18 | |||
| 19 | public static function fromScalarArray(array $value): self |
||
| 20 | { |
||
| 21 | return new self( |
||
| 22 | ...array_map( |
||
| 23 | function (string $host) { |
||
| 24 | return Hostname::parse($host); |
||
| 25 | }, |
||
| 26 | $value |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | |||
| 31 | public static function fromString(string $string): self |
||
| 32 | { |
||
| 33 | return self::fromScalarArray(array_map('trim', explode(',', $string))); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function toString(): string |
||
| 37 | { |
||
| 38 | return implode(',', $this->hostnames); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function __toString() |
||
| 42 | { |
||
| 43 | return $this->toString(); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function toLocal(): HostnameCollection |
||
| 47 | { |
||
| 48 | $localHosts = []; |
||
| 49 | foreach ($this->hostnames as $value) { |
||
| 50 | $localHosts[] = $value->toLocal(); |
||
| 51 | } |
||
| 52 | |||
| 53 | return new self(...$localHosts); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function getIterator() |
||
| 59 | } |
||
| 60 | |||
| 61 | public function count() |
||
| 64 | } |
||
| 65 | |||
| 66 | } |
||
| 67 |