| Conditions | 23 |
| Paths | 23 |
| Total Lines | 79 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| 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 |
||
| 63 | public function getFunctions() |
||
| 64 | { |
||
| 65 | $count = count($this->tokens); |
||
| 66 | $bufferFunctions = array(); |
||
| 67 | /* @var ParsedFunction[] $bufferFunctions */ |
||
| 68 | $functions = array(); |
||
| 69 | /* @var ParsedFunction[] $functions */ |
||
| 70 | |||
| 71 | for ($k = 0; $k < $count; ++$k) { |
||
| 72 | $value = $this->tokens[$k]; |
||
| 73 | |||
| 74 | if (is_string($value)) { |
||
| 75 | if (isset($bufferFunctions[0])) { |
||
| 76 | switch ($value) { |
||
| 77 | case ',': |
||
| 78 | $bufferFunctions[0]->nextArgument(); |
||
| 79 | break; |
||
| 80 | case ')': |
||
| 81 | $functions[] = array_shift($bufferFunctions)->close(); |
||
| 82 | break; |
||
| 83 | case '.': |
||
| 84 | break; |
||
| 85 | default: |
||
| 86 | $bufferFunctions[0]->stopArgument(); |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | |||
| 93 | switch ($value[0]) { |
||
| 94 | case T_CONSTANT_ENCAPSED_STRING: |
||
| 95 | //add an argument to the current function |
||
| 96 | if (isset($bufferFunctions[0])) { |
||
| 97 | $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); |
||
| 98 | } |
||
| 99 | break; |
||
| 100 | case T_STRING: |
||
| 101 | if (isset($bufferFunctions[0])) { |
||
| 102 | $bufferFunctions[0]->stopArgument(); |
||
| 103 | } |
||
| 104 | //new function found |
||
| 105 | for ($j = $k + 1; $j < $count; ++$j) { |
||
| 106 | $nextToken = $this->tokens[$j]; |
||
| 107 | if (is_array($nextToken) && $nextToken[0] === T_COMMENT) { |
||
| 108 | continue; |
||
| 109 | } |
||
| 110 | if ($nextToken === '(') { |
||
| 111 | $newFunction = new ParsedFunction($value[1], $value[2]); |
||
| 112 | if ($k > 0 && is_array($this->tokens[$k - 1]) && $this->tokens[$k - 1][0] === T_COMMENT) { |
||
| 113 | $comment = $this->parsePhpComment($this->tokens[$k - 1][1]); |
||
| 114 | if ($comment !== null) { |
||
| 115 | $newFunction->addComment($comment); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | array_unshift($bufferFunctions, $newFunction); |
||
| 119 | $k = $j; |
||
| 120 | } |
||
| 121 | break; |
||
| 122 | } |
||
| 123 | break; |
||
| 124 | case T_COMMENT: |
||
| 125 | if (isset($bufferFunctions[0])) { |
||
| 126 | $comment = $this->parsePhpComment($value[1]); |
||
| 127 | if ($comment !== null) { |
||
| 128 | $bufferFunctions[0]->addComment($comment); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | break; |
||
| 132 | default: |
||
| 133 | if (isset($bufferFunctions[0])) { |
||
| 134 | $bufferFunctions[0]->stopArgument(); |
||
| 135 | } |
||
| 136 | break; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | return $functions; |
||
| 141 | } |
||
| 142 | |||
| 164 |