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 ( 994736...366350 )
by François
08:25 queued 05:01
created

Config::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
19
namespace fkooman\RemoteStorage;
20
21
use fkooman\RemoteStorage\Exception\ConfigException;
22
use Symfony\Component\Yaml\Yaml;
23
24
class Config
25
{
26
    /** @var array */
27
    protected $configData;
28
29
    public function __construct(array $configData)
30
    {
31
        $this->configData = $configData;
32
        $this->configData = array_merge(static::defaultConfig(), $configData);
33
    }
34
35
    public static function defaultConfig()
36
    {
37
        return [];
38
    }
39
40
    public function hasSection($key)
41
    {
42
        if (!array_key_exists($key, $this->configData)) {
43
            throw new ConfigException(sprintf('section "%s" not available', $key));
44
        }
45
46
        return is_array($this->configData[$key]);
47
    }
48
49
    public function getSection($key)
50
    {
51
        if (false === $this->hasSection($key)) {
52
            throw new ConfigException(sprintf('"%s" is not a section', $key));
53
        }
54
55
        // do not return the parent object if we were subclassed, but an actual
56
        // "Config" object to avoid copying in the defaults if set
57
        return new self($this->configData[$key]);
58
    }
59
60
    public function hasItem($key)
61
    {
62
        return array_key_exists($key, $this->configData);
63
    }
64
65
    public function getItem($key)
66
    {
67
        if (false === $this->hasItem($key)) {
68
            throw new ConfigException(sprintf('item "%s" not available', $key));
69
        }
70
71
        return $this->configData[$key];
72
    }
73
74
    public static function fromFile($configFile)
75
    {
76
        if (false === $fileContent = @file_get_contents($configFile)) {
77
            throw new ConfigException(sprintf('unable to read "%s"', $configFile));
78
        }
79
80
        return new static(Yaml::parse($fileContent));
81
    }
82
83
    public function toArray()
84
    {
85
        return $this->configData;
86
    }
87
88
    public static function toFile($configFile, array $configData)
89
    {
90
        $fileData = Yaml::dump($configData, 3);
91
        if (false === @file_put_contents($configFile, $fileData)) {
92
            throw new ConfigException(sprintf('unable to write "%s"', $configFile));
93
        }
94
    }
95
}
96