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 ( 36987f...5a4612 )
by François
03:22
created

PoolConfig::__construct()   C

Complexity

Conditions 8
Paths 26

Size

Total Lines 38
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 38
rs 5.3846
cc 8
eloc 21
nc 26
nop 1
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
18
namespace fkooman\VPN\Server\Config;
19
20
use InvalidArgumentException;
21
22
class PoolConfig
23
{
24
    /** @var string */
25
    private $name;
26
27
    /** @var IP */
28
    private $range;
29
30
    /** @var array */
31
    private $dstNet4;
32
33
    /** @var array */
34
    private $dstNet6;
35
36
    /** @var array */
37
    private $dstPort;
38
39
    public function __construct(array $c)
40
    {
41
        if (!array_key_exists('name', $c)) {
42
            throw new InvalidArgumentException('missing "name"');
43
        }
44
        $this->name = $c['name'];
45
46
        if (!array_key_exists('range', $c)) {
47
            throw new InvalidArgumentException('missing "range"');
48
        }
49
        // XXX validate range
50
        $this->range = new IP($c['range']);
51
52
        // default values
53
        if (!array_key_exists('firewall', $c)) {
54
            $c['firewall'] = [];
55
        }
56
        if (!array_key_exists('dst_net', $c['firewall'])) {
57
            $c['firewall']['dst_net'] = ['0.0.0.0/0', '::/0'];
58
        }
59
        if (!array_key_exists('dst_port', $c['firewall'])) {
60
            $c['firewall']['dst_port'] = [];
61
        }
62
63
        $this->dstNet4 = [];
64
        $this->dstNet6 = [];
65
66
        foreach ($c['firewall']['dst_net'] as $dstNet) {
67
            // XXX validate the nets
68
            if (false !== strpos($dstNet, ':')) {
69
                $this->dstNet6[] = $dstNet;
70
            } else {
71
                $this->dstNet4[] = $dstNet;
72
            }
73
        }
74
75
        $this->dstPort = $c['firewall']['dst_port'];
76
    }
77
78
    public function getName()
79
    {
80
        return $this->name;
81
    }
82
83
    public function getRange()
84
    {
85
        return $this->range;
86
    }
87
88
    public function getDstNet4()
89
    {
90
        return $this->dstNet4;
91
    }
92
93
    public function getDstNet6()
94
    {
95
        return $this->dstNet6;
96
    }
97
98
    public function getDstPort()
99
    {
100
        return $this->dstPort;
101
    }
102
103
    public function useDefaultGateway()
104
    {
105
        return in_array('0.0.0.0/0', $this->dstNet4) || in_array('::/0', $this->dstNet6);
106
    }
107
}
108