GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Range   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 29
c 0
b 0
f 0
rs 10
ccs 14
cts 14
cp 1
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 6 3
A expand() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
/* (c) Anton Medvedev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Deployer\Host;
12
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
37
    {
38 3
        if ($zeroBased) {
39
            return strlen($i) === 1 ? "0$i" : $i;
40
        } else {
41
            return $i;
42
        }
43
    }
44
}
45