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 — develop ( a922e7...d85b3d )
by Alexander
01:50
created

Result::findAll()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 9
c 0
b 0
f 0
nc 5
nop 1
dl 0
loc 18
ccs 9
cts 9
cp 1
crap 4
rs 9.2
1
<?php
2
/**
3
 * @package GetSky\ParserExpressions
4
 * @author  Alexander Getmansky <[email protected]>
5
 */
6
namespace GetSky\ParserExpressions;
7
8
/**
9
 * Result class is used to store the result of the parse.
10
 */
11
class Result implements \Iterator, ResultInterface
12
{
13
14
    /**
15
     * @var string Result string
16
     */
17
    protected $name;
18
    /**
19
     * @var string Result string
20
     */
21
    protected $value;
22
    /**
23
     * @var integer Start position
24
     */
25
    protected $start;
26
    /**
27
     * @var integer Final position
28
     */
29
    protected $end;
30
    /**
31
     * @var Result[]
32
     */
33
    protected $children = [];
34
    /**
35
     * @var integer
36
     */
37
    private $key = 0;
38
39
    /**
40
     * @param string $name
41
     */
42 27
    public function __construct($name)
43
    {
44 27
        $this->name = $name;
45 27
    }
46
47
    /**
48
     * @return string
49
     */
50 3
    public function getValue()
51
    {
52 3
        return $this->value;
53
    }
54
55
    /**
56
     * @param string $value
57
     * @param integer $start
58
     */
59 9
    public function setValue($value, $start)
60
    {
61 9
        $this->value = (string)$value;
62 9
        $this->start = $start;
63 9
        $this->end = $start + strlen($value);
64 9
    }
65
66
    /**
67
     * @return string
68
     */
69 8
    public function getName()
70
    {
71 8
        return $this->name;
72
    }
73
74
    /**
75
     * Added child result
76
     *
77
     * @param Result $child
78
     */
79 17
    public function addChild(Result $child)
80
    {
81 17
        $this->children[] = $child;
82 17
    }
83
84
    /**
85
     * @return Result
86
     */
87 3
    public function current()
88
    {
89 3
        return $this->children[$this->key];
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 4
    public function next()
96
    {
97 4
        ++$this->key;
98 4
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103 4
    public function key()
104
    {
105 4
        return $this->key;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 4
    public function valid()
112
    {
113 4
        return isset($this->children[$this->key]);
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119 4
    public function rewind()
120
    {
121 4
        $this->key = 0;
122 4
    }
123
124
    /**
125
     * Outstanding results in an array.
126
     *
127
     * @return array
128
     */
129 4
    public function toArray()
130
    {
131
        $array = [
132 4
            'name' => $this->name,
133 4
            'value' => $this->value,
134 4
            'start' => $this->start,
135 4
            'end' => $this->end,
136
        ];
137
138 4
        foreach ($this->children as $rule) {
139 3
            $array['children'][] = $rule->toArray();
140
        }
141
142 4
        return $array;
143
    }
144
145
    /**
146
     * Search for the first result by name.
147
     *
148
     * @param $ruleName
149
     * @return Result|null
150
     */
151 4
    public function find($ruleName)
152
    {
153
154 4
        foreach ($this->children as $rule) {
155 3
            if ($rule->getName() == $ruleName) {
156 2
                return $rule;
157
            }
158
159 3
            $child = $rule->find($ruleName);
160 3
            if ($child !== null) {
161 3
                return $child;
162
            }
163
        }
164
165 4
        return null;
166
    }
167
168
    /**
169
     * Search results by name.
170
     *
171
     * @param $ruleName
172
     * @return Result|null
173
     */
174 4
    public function findAll($ruleName)
175
    {
176
177 4
        $result = [];
178
179 4
        foreach ($this->children as $rule) {
180 3
            if ($rule->getName() == $ruleName) {
181 2
                $result[] = $rule;
182
            }
183
184 3
            $child = $rule->findAll($ruleName);
185 3
            if ($child !== null) {
186 3
                $result = array_merge($result, $child);
187
            }
188
        }
189
190 4
        return $result;
191
    }
192
}
193