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 ( e70437...b53fd1 )
by Anton
03:00
created

Collection   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 120
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B get() 0 23 6
A has() 0 9 2
A set() 0 4 1
A getIterator() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A count() 0 4 1
A toArray() 0 4 1
1
<?php
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\Collection;
9
10
class Collection implements CollectionInterface, \Countable
11
{
12
    /**
13
     * @var array
14
     */
15
    private $collection = [];
16
17
    /**
18
     * Collection constructor.
19
     * @param array $collection
20 50
     */
21
    public function __construct(array $collection = [])
22 50
    {
23 45
        $this->collection = $collection;
24
    }
25 5
26 5
    /**
27 5
     * {@inheritdoc}
28
     */
29
    public function get($name)
30
    {
31
        if ($this->has($name)) {
32
            if (strpos($name, '.') === false) {
33
                return $this->collection[$name];
34 51
            } else {
35
                $parts = explode('.', $name);
36 51
                $scope = &$this->collection;
37
                $count = count($parts) - 1;
38
                for ($i = 0; $i < $count; $i++) {
39
                    if (!isset($scope[$parts[$i]])) {
40
                        return null;
41
                    }
42 46
                    $scope = &$scope[$parts[$i]];
43
                }
44 46
                return isset($scope[$parts[$i]]) ? $scope[$parts[$i]] : null;
45 46
            }
46
        } else {
47
            $class = explode('\\', static::class);
48
            $class = end($class);
49
            throw new \RuntimeException("Object `$name` does not exist in $class.");
50 25
        }
51
    }
52 25
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function has($name)
57
    {
58 1
        if (strpos($name, '.') === false) {
59
            return array_key_exists($name, $this->collection);
60 1
        } else {
61
            list($head,) = explode('.', $name);
62
            return array_key_exists($head, $this->collection);
63
        }
64
    }
65
66 40
    /**
67
     * {@inheritdoc}
68 40
     */
69
    public function set($name, $object)
70
    {
71
        $this->collection[$name] = $object;
72
    }
73
74 41
    /**
75
     * {@inheritdoc}
76 41
     */
77 41
    public function getIterator()
78
    {
79
        return new \ArrayIterator($this->collection);
80
    }
81
82 1
    /**
83
     * {@inheritdoc}
84 1
     */
85 1
    public function offsetExists($offset)
86
    {
87
        return $this->has($offset);
88
    }
89
90 2
    /**
91
     * {@inheritdoc}
92 2
     */
93
    public function offsetGet($offset)
94
    {
95
        return $this->get($offset);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function offsetSet($offset, $value)
102
    {
103
        $this->set($offset, $value);
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function offsetUnset($offset)
110
    {
111
        unset($this->collection[$offset]);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function count()
118
    {
119
        return count($this->collection);
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function toArray()
126
    {
127
        return iterator_to_array($this);
128
    }
129
}
130