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::expand()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 10
nc 4
nop 1
dl 0
loc 17
c 0
b 0
f 0
cc 4
rs 9.9332
ccs 9
cts 9
cp 1
crap 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