| Conditions | 10 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 68 | public function getFunctions() |
||
| 69 | { |
||
| 70 | $count = count($this->tokens); |
||
| 71 | $bufferFunctions = array(); |
||
| 72 | $functions = array(); |
||
| 73 | |||
| 74 | for ($k = 0; $k < $count; ++$k) { |
||
| 75 | $value = $this->tokens[$k]; |
||
| 76 | |||
| 77 | //close the current function |
||
| 78 | if (is_string($value)) { |
||
| 79 | if ($value === ')' && isset($bufferFunctions[0])) { |
||
| 80 | $functions[] = array_shift($bufferFunctions); |
||
| 81 | } |
||
| 82 | |||
| 83 | continue; |
||
| 84 | } |
||
| 85 | |||
| 86 | //add an argument to the current function |
||
| 87 | if (isset($bufferFunctions[0]) && ($value[0] === T_CONSTANT_ENCAPSED_STRING)) { |
||
| 88 | $bufferFunctions[0][2][] = static::decodeString($value[1]); |
||
| 89 | continue; |
||
| 90 | } |
||
| 91 | |||
| 92 | //new function found |
||
| 93 | if (($value[0] === T_STRING) && is_string($this->tokens[$k + 1]) && ($this->tokens[$k + 1] === '(')) { |
||
| 94 | array_unshift($bufferFunctions, array($value[1], $value[2], array())); |
||
| 95 | ++$k; |
||
| 96 | |||
| 97 | continue; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $functions; |
||
| 102 | } |
||
| 103 | } |
||
| 104 |