| Total Complexity | 7 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | class Range |
||
| 14 | 16 | { |
|
| 15 | public const PATTERN = '/\[(.+?)\]/'; |
||
| 16 | 16 | ||
| 17 | 16 | public static function expand(array $hostnames): array |
|
| 18 | 16 | { |
|
| 19 | 3 | $expanded = []; |
|
| 20 | 3 | foreach ($hostnames as $hostname) { |
|
| 21 | if (preg_match(self::PATTERN, $hostname, $matches)) { |
||
| 22 | 3 | [$start, $end] = explode(':', $matches[1]); |
|
| 23 | 3 | $zeroBased = (bool) preg_match('/^0[1-9]/', $start); |
|
| 24 | |||
| 25 | foreach (range($start, $end) as $i) { |
||
| 26 | 15 | $expanded[] = preg_replace(self::PATTERN, self::format((string) $i, $zeroBased), $hostname); |
|
| 27 | } |
||
| 28 | } else { |
||
| 29 | $expanded[] = $hostname; |
||
| 30 | 16 | } |
|
| 31 | } |
||
| 32 | |||
| 33 | 3 | return $expanded; |
|
| 34 | } |
||
| 35 | 3 | ||
| 36 | 1 | private static function format(string $i, bool $zeroBased): string |
|
| 42 | } |
||
| 43 | } |
||
| 45 |