| Conditions | 16 |
| Paths | 24 |
| Total Lines | 34 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 58 | protected function parseValues(array &$values) |
||
| 59 | { |
||
| 60 | foreach ($values as &$value) { |
||
| 61 | if (is_array($value)) { |
||
| 62 | $this->parseValues($value); |
||
| 63 | } elseif (is_string($value) && substr($value, 0, 1) === '<' && substr($value, -1) === '>') { |
||
| 64 | $functionId = null; |
||
| 65 | $parameters = []; |
||
| 66 | foreach (token_get_all('<?php ' . $value) as $token) { |
||
| 67 | if (is_array($token)) { |
||
| 68 | if ($token[0] === T_STRING && $functionId === null) { |
||
| 69 | $functionId = $token[1]; |
||
| 70 | } elseif ($token[0] === T_STRING) { |
||
| 71 | $parameters[] = $token[1]; |
||
| 72 | } elseif ($token[0] === T_CONSTANT_ENCAPSED_STRING) { |
||
| 73 | $parameters[] = substr($token[1], 1, -1); |
||
| 74 | } elseif ($token[0] === T_LNUMBER || $token[0] === T_DNUMBER) { |
||
| 75 | $parameters[] = $token[1]; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($functionId === null) { |
||
| 81 | throw new FunctionIdNotFoundException('Function name cannont be found in ' . $value . '.'); |
||
| 82 | } elseif (isset(static::$functions[$functionId]) === false) { |
||
| 83 | throw new FunctionNotFoundException('Function "' . $functionId . '" not found.'); |
||
| 84 | } |
||
| 85 | |||
| 86 | $value = call_user_func_array(static::$functions[$functionId], $parameters); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | return $this; |
||
| 91 | } |
||
| 92 | } |
||
| 93 |