Conditions | 16 |
Paths | 29 |
Total Lines | 61 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
147 | private function parse(string $func): void |
||
148 | { |
||
149 | $level = 0; |
||
150 | $start = $name = $value = null; |
||
151 | foreach ($this->tokens as $position => $token) { |
||
152 | if (!is_array($token)) { |
||
153 | $token = [$token, $token, 0]; |
||
154 | } |
||
155 | |||
156 | switch ($token[0]) { |
||
157 | case '(': |
||
158 | if ($start !== null) { |
||
159 | $level++; |
||
160 | $value .= $token[1]; |
||
161 | } |
||
162 | break; |
||
163 | case ')': |
||
164 | if ($start === null) { |
||
165 | break; |
||
166 | } |
||
167 | |||
168 | $level--; |
||
169 | $value .= $token[1]; |
||
170 | if ($level === 0) { |
||
171 | $this->blocks[$name] = [ |
||
172 | 'start' => $start, |
||
173 | 'value' => trim($value), |
||
174 | 'end' => $position |
||
175 | ]; |
||
176 | |||
177 | // reset |
||
178 | $start = $name = $value = null; |
||
179 | } |
||
180 | break; |
||
181 | case T_STRING: |
||
182 | if ($token[1] === $func) { |
||
183 | $start = $position; |
||
184 | $value = $token[1]; |
||
185 | break; |
||
186 | } |
||
187 | |||
188 | if ($start !== null) { |
||
189 | $value .= $token[1]; |
||
190 | } |
||
191 | break; |
||
192 | case T_CONSTANT_ENCAPSED_STRING: |
||
193 | if ($start === null) { |
||
194 | break; |
||
195 | } |
||
196 | |||
197 | if ($name === null) { |
||
198 | $name = stripcslashes(substr($token[1], 1, -1)); |
||
199 | } |
||
200 | $value .= $token[1]; |
||
201 | break; |
||
202 | case ',': |
||
203 | $value .= $token[1]; |
||
204 | break; |
||
205 | default: |
||
206 | if ($start !== null) { |
||
207 | $value .= $token[1]; |
||
208 | } |
||
213 |