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.
Completed
Push — master ( bca83a...1ac405 )
by François
03:36
created

AddressPool   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIp4() 0 15 3
A getIp6() 0 18 3
1
<?php
2
/**
3
 * Copyright 2015 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
namespace fkooman\VPN\Server\Config;
18
19
use InvalidArgumentException;
20
21
class AddressPool
22
{
23
    /**
24
     * Find the first free IPv4 address.
25
     *
26
     * @param string $startIp the IPv4 address to start from
27
     * @param string $endIp   the IPv4 address to end at, i.e. limiting the range
28
     * @param array  $usedIp  array of IPv4 addresses already in use
29
     *
30
     * @return string|false the assigned IPv4 address or false when no address
31
     *                      is available
32
     */
33
    public static function getIp4($startIp, $endIp, $usedIp = array())
34
    {
35
        $s = ip2long($startIp);
36
        $e = ip2long($endIp);
37
38
        $search = $s;
39
        while (in_array(long2ip($search), $usedIp)) {
40
            ++$search;
41
            if ($search > $e) {
42
                return false;
43
            }
44
        }
45
46
        return long2ip($search);
47
    }
48
49
    /**
50
     * Give a matching IPv6 address for the obtained IPv4 address.
51
     *
52
     * @param string $v6 the expanded first 64 bits of an IPv6 address 
53
     *                   (network), e.g. "fd00:4242:4242:4242"
54
     * @param string $v4 the IPv4 address to use in the IPv6 address
55
     *
56
     * @return string the IPv6 address containing the IPv4 address
57
     */
58
    public static function getIp6($v6, $v4)
59
    {
60
        if (3 !== substr_count($v6, ':')) {
61
            throw new InvalidArgumentException('specify the expanded network part of a /64 IPv6 address');
62
        }
63
        if (3 !== substr_count($v4, '.')) {
64
            throw new InvalidArgumentException('invalid IPv4 address');
65
        }
66
67
        $v6e = explode(':', $v6);
68
        $v4e = explode('.', $v4);
69
70
        $v4v6 = sprintf(
71
            '%s:%s:%s:%s:%s:%s:%s:%s', $v6e[0], $v6e[1], $v6e[2], $v6e[3], $v4e[0], $v4e[1], $v4e[2], $v4e[3]
72
        );
73
74
        return $v4v6;
75
    }
76
}
77
78
#try {
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
#    $ip4 = AddressPool::getIp4(
80
#        '10.42.42.128',
81
#        '10.42.42.132',
82
#        array(
83
#            '10.42.42.128',
84
#            '10.42.42.129',
85
#            '10.42.42.130',
86
#            '10.42.42.131',
87
#            //'10.42.42.132',
88
#        )
89
#    );
90
91
#    $ip6 = AddressPool::getIp6(
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
#        'fd00:4242:4242:4242',
93
#        $ip4
94
#    );
95
96
#    echo sprintf('IPv4: %s', $ip4).PHP_EOL;
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
#    echo sprintf('IPv6: %s', $ip6).PHP_EOL;
98
#} catch (Exception $e) {
99
#    echo $e->getMessage().PHP_EOL;
100
#    exit(1);
101
#}
102
103