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.
Passed
Pull Request — master (#1061)
by Maxim
04:23 queued 01:35
created

Collection::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
     */
21 50
    public function __construct(array $collection = [])
22
    {
23 50
        $this->collection = $collection;
24 50
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 44
    public function get($name)
30
    {
31 44
        if ($this->has($name)) {
32 40
            if (strpos($name, '.') === false) {
33 40
                return $this->collection[$name];
34
            } else {
35
                $parts = explode('.', $name);
36
                $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
                    $scope = &$scope[$parts[$i]];
43
                }
44
                return isset($scope[$parts[$i]]) ? $scope[$parts[$i]] : null;
45
            }
46
        } else {
47 4
            $class = explode('\\', static::class);
48 4
            $class = end($class);
49 4
            throw new \RuntimeException("Object `$name` does not exist in $class.");
50
        }
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 47
    public function has($name)
57
    {
58 47
        if (strpos($name, '.') === false) {
59 47
            return array_key_exists($name, $this->collection);
60
        } else {
61
            list($head, ) = explode('.', $name);
62
            return array_key_exists($head, $this->collection);
63
        }
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 54
    public function set($name, $object)
70
    {
71 54
        $this->collection[$name] = $object;
72 54
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 22
    public function getIterator()
78
    {
79 22
        return new \ArrayIterator($this->collection);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 26
    public function offsetExists($offset)
86
    {
87 26
        return $this->has($offset);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 31
    public function offsetGet($offset)
94
    {
95 31
        return $this->get($offset);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 50
    public function offsetSet($offset, $value)
102
    {
103 50
        $this->set($offset, $value);
104 50
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 2
    public function offsetUnset($offset)
110
    {
111 2
        unset($this->collection[$offset]);
112 2
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 2
    public function count()
118
    {
119 2
        return count($this->collection);
120
    }
121
122
    /**
123
     * @return array
124
     */
125 1
    public function toArray()
126
    {
127 1
        return iterator_to_array($this);
128
    }
129
}
130