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 10
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 10
cts 10
cp 1
crap 4
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Host;
9
10
class Range
11
{
12
    const PATTERN = '/\[(.+?)\]/';
13
14 16
    public static function expand(array $hostnames)
15
    {
16 16
        $expanded = [];
17 16
        foreach ($hostnames as $hostname) {
18 16
            if (preg_match(self::PATTERN, $hostname, $matches)) {
19 3
                list($start, $end) = explode(':', $matches[1]);
20 3
                $zeroBased = preg_match('/^0[1-9]/', $start);
21
22 3
                foreach (range($start, $end) as $i) {
23 3
                    $expanded[] = preg_replace(self::PATTERN, self::format($i, $zeroBased), $hostname);
24
                }
25
            } else {
26 15
                $expanded[] = $hostname;
27
            }
28
        }
29
30 16
        return $expanded;
31
    }
32
33 3
    private static function format($i, $zeroBased)
34
    {
35 3
        if ($zeroBased) {
36 1
            return strlen($i) === 1 ? "0$i" : $i;
37
        } else {
38 3
            return $i;
39
        }
40
    }
41
}
42