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

IPv4   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRange() 0 4 1
A getDns() 0 4 1
A getPool() 0 4 1
A getPools() 0 4 1
B parseConfig() 0 20 5
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
class IPv4
21
{
22
    /** @var IP */
23
    private $range;
24
25
    /** @var array */
26
    private $dns;
27
28
    /** @var array */
29
    private $pools;
30
31
    public function __construct(array $input)
32
    {
33
        $this->parseConfig($input);
34
    }
35
36
    public function getRange()
37
    {
38
        return $this->range;
39
    }
40
41
    public function getDns()
42
    {
43
        return $this->dns;
44
    }
45
46
    public function getPool($id)
47
    {
48
        return $this->pools[$id];
49
    }
50
51
    public function getPools()
52
    {
53
        return $this->pools;
54
    }
55
56
    /**
57
     * Parse and validate the configuration and set default values if they
58
     * are missing from the configuration file.
59
     */
60
    private function parseConfig(array $input)
61
    {
62
        foreach (['range', 'pools'] as $k) {
63
            if (!array_key_exists($k, $input)) {
64
                throw new RuntimeException(sprintf('missing key "%s" in configuration', $k));
65
            }
66
        }
67
68
        $this->range = new IP($input['range']);
69
70
        if (!array_key_exists('dns', $input)) {
71
            $input['dns'] = ['8.8.8.8', '8.8.4.4'];
72
        }
73
        $this->dns = $input['dns'];
74
75
        $this->pools = [];
76
        foreach ($input['pools'] as $k => $v) {
77
            $this->pools[$k] = new PoolConfig($v);
78
        }
79
    }
80
}
81