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.
Test Failed
Push — master ( 09a43c...4f79d5 )
by Anton
03:00
created

Configuration::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Configuration;
9
10
use Deployer\Collection\Collection;
11
use Deployer\Deployer;
12
use Deployer\Exception\ConfigurationException;
13
use function Deployer\Support\array_merge_alternate;
14
use function Deployer\Support\is_closure;
15
16
class Configuration implements \ArrayAccess
17
{
18
    private $parent;
19
    private $values = [];
20
21 42
    public function __construct(Configuration $parent = null)
22
    {
23 42
        $this->parent = $parent;
24 42
    }
25
26 42
    public function set(string $name, $value)
27
    {
28 42
        $this->values[$name] = $value;
29 42
    }
30
31 17 View Code Duplication
    public function has(string $name): bool
32
    {
33 17
        $ok = array_key_exists($name, $this->values);
34 17
        if ($ok) {
35 13
            return true;
36
        }
37 10
        if ($this->parent) {
38 7
            return $this->parent->has($name);
39
        }
40 8
        return false;
41
    }
42
43 8
    public function add(string $name, array $array)
44
    {
45 8
        if ($this->has($name)) {
46 7
            $config = $this->get($name);
47 7
            if (!is_array($config)) {
48 2
                throw new ConfigurationException("Config option \"$name\" isn't array.");
49
            }
50 5
            $this->set($name, array_merge_alternate($config, $array));
51
        } else {
52 1
            $this->set($name, $array);
53
        }
54 6
    }
55
56 32
    public function get(string $name, $default = null)
57
    {
58 32
        if (array_key_exists($name, $this->values)) {
59 30
            if (is_closure($this->values[$name])) {
60 2
                return $this->values[$name] = $this->parse(call_user_func($this->values[$name]));
61
            } else {
62 30
                return $this->parse($this->values[$name]);
63
            }
64
        }
65
66 17
        if ($this->parent) {
67 12
            $rawValue = $this->parent->fetch($name);
68 12
            if ($rawValue !== null) {
69 11
                if (is_closure($rawValue)) {
70 5
                    return $this->values[$name] = $this->parse(call_user_func($rawValue));
71
                } else {
72 10
                    return $this->values[$name]= $this->parse($rawValue);
73
                }
74
            }
75
        }
76
77 12
        if ($default !== null) {
78 11
            return $this->parse($default);
79
        }
80
81 2
        throw new ConfigurationException("Config option \"$name\" does not exist.");
82
    }
83
84 12 View Code Duplication
    protected function fetch($name)
85
    {
86 12
        if (array_key_exists($name, $this->values)) {
87 11
            return $this->values[$name];
88
        }
89 8
        if ($this->parent) {
90 1
            return $this->parent->fetch($name);
91
        }
92 7
        return null;
93
    }
94
95 31
    public function parse($value)
96
    {
97 31
        if (is_string($value)) {
98 26
            return preg_replace_callback('/\{\{\s*([\w\.\/-]+)\s*\}\}/', [$this, 'parseCallback'], $value);
99
        }
100
101 20
        return $value;
102
    }
103
104 10
    private function parseCallback(array $matches)
105
    {
106 10
        return isset($matches[1]) ? $this->get($matches[1]) : null;
107
    }
108
109 8
    public function offsetExists($offset)
110
    {
111 8
        return $this->has($offset);
112
    }
113
114 9
    public function offsetGet($offset)
115
    {
116 9
        return $this->get($offset);
117
    }
118
119 17
    public function offsetSet($offset, $value)
120
    {
121 17
        $this->set($offset, $value);
122 17
    }
123
124 1
    public function offsetUnset($offset)
125
    {
126 1
        unset($this->values[$offset]);
127 1
    }
128
129 7
    public function persist()
130
    {
131 7
        $values = [];
132 7
        if ($this->parent !== null) {
133 7
            $values = $this->parent->persist();
134
        }
135 7
        foreach ($this->values as $key => $value) {
136 7
            if (is_closure($value)) {
137 7
                continue;
138
            }
139 7
            $values[$key] = $value;
140
        }
141 7
        return $values;
142
    }
143
144 5
    public function load()
145
    {
146 5
        $file = $this->configFile();
147 5
        if (file_exists($file)) {
148 4
            $this->values = json_decode(file_get_contents($file), true);
149
        }
150 5
    }
151
152 6
    public function save()
153
    {
154 6
        file_put_contents($this->configFile(), json_encode($this->persist()));
155 6
    }
156
157 6
    private function configFile() {
158 6
        return sprintf('%s/%s.dep', $this->get('config_directory'), str_replace(DIRECTORY_SEPARATOR, "_", $this->get('alias')));
159
    }
160
}
161