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 ( 379137...b7f8f1 )
by François
02:12
created

Config::v()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
cc 6
eloc 12
nc 5
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
namespace SURFnet\VPN\Common;
19
20
use Symfony\Component\Yaml\Yaml;
21
use SURFnet\VPN\Common\Exception\ConfigException;
22
use InvalidArgumentException;
23
use RuntimeException;
24
25
class Config
26
{
27
    /** @var array */
28
    protected $configData;
29
30
    public function __construct(array $configData)
31
    {
32
        $this->configData = array_merge(static::defaultConfig(), $configData);
33
    }
34
35
    public static function defaultConfig()
36
    {
37
        return [];
38
    }
39
40
    /**
41
     * Get a configuration value.
42
     */
43
    public function v()
44
    {
45
        $argv = func_get_args();
46
        // if no parameters are requested, return everything
47
        if (0 === count($argv)) {
48
            return $this->configData;
49
        }
50
51
        $configPointer = $this->configData;
52
        foreach ($argv as $arg) {
53
            if (!is_string($arg)) {
54
                throw new InvalidArgumentException('requested configuration field must be string');
55
            }
56
            if (!is_array($configPointer) || !array_key_exists($arg, $configPointer)) {
57
                throw new ConfigException(sprintf('missing configuration field "%s"', implode(',', $argv)));
58
            }
59
            $configPointer = $configPointer[$arg];
60
        }
61
62
        return $configPointer;
63
    }
64
65
    /**
66
     * Check if a configuration value exists.
67
     */
68
    public function e()
69
    {
70
        $argv = func_get_args();
71
        if (0 === count($argv)) {
72
            return true;
73
        }
74
75
        $configPointer = $this->configData;
76
        foreach ($argv as $arg) {
77
            if (!is_string($arg)) {
78
                throw new InvalidArgumentException('requested configuration field must be string');
79
            }
80
            if (!is_array($configPointer) || !array_key_exists($arg, $configPointer)) {
81
                return false;
82
            }
83
            $configPointer = $configPointer[$arg];
84
        }
85
86
        return true;
87
    }
88
89
    public static function fromFile($configFile)
90
    {
91
        $fileContent = FileIO::readFile($configFile);
92
        $parsedConfig = Yaml::parse($fileContent);
93
        if (!is_array($parsedConfig)) {
94
            throw new RuntimeException(sprintf('invalid configuration file format in "%s"', $configFile));
95
        }
96
97
        return new static($parsedConfig);
98
    }
99
100
    public static function toFile($configFile, array $configData)
101
    {
102
        $yamlData = Yaml::dump($configData);
103
        FileIO::writeFile($configFile, $yamlData);
104
    }
105
}
106