| Conditions | 19 |
| Paths | 18 |
| Total Lines | 58 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 22 | public function getFunctions() |
||
| 23 | { |
||
| 24 | $count = count($this->tokens); |
||
| 25 | $bufferFunctions = array(); |
||
| 26 | $functions = array(); |
||
| 27 | $concatenating = false; |
||
| 28 | |||
| 29 | for ($k = 0; $k < $count; ++$k) { |
||
| 30 | $value = $this->tokens[$k]; |
||
| 31 | |||
| 32 | if (is_string($value)) { |
||
| 33 | if ($value === '.') { |
||
| 34 | //concatenating strings |
||
| 35 | $concatenating = true; |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | $concatenating = false; |
||
| 39 | if ($value === ')' && isset($bufferFunctions[0])) { |
||
| 40 | //close the current function |
||
| 41 | $functions[] = array_shift($bufferFunctions); |
||
| 42 | } |
||
| 43 | continue; |
||
| 44 | } |
||
| 45 | |||
| 46 | switch ($value[0]) { |
||
| 47 | case T_CONSTANT_ENCAPSED_STRING: |
||
| 48 | //add an argument to the current function |
||
| 49 | if (isset($bufferFunctions[0])) { |
||
| 50 | $string = \Gettext\Extractors\PhpCode::convertString($value[1]); |
||
| 51 | if ($concatenating && !empty($bufferFunctions[0][2])) { |
||
| 52 | $bufferFunctions[0][2][count($bufferFunctions[0][2]) - 1] .= $string; |
||
| 53 | } else { |
||
| 54 | $bufferFunctions[0][2][] = $string; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | break; |
||
| 58 | case T_STRING: |
||
| 59 | //new function found |
||
| 60 | for ($j = $k + 1; $j < $count; $j++) { |
||
| 61 | $nextToken = $this->tokens[$j]; |
||
| 62 | if (is_array($nextToken) && ($nextToken[0] === T_COMMENT || $nextToken[0] === T_WHITESPACE)) { |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | if ($nextToken === '(') { |
||
| 66 | array_unshift($bufferFunctions, array($value[1], $value[2], array())); |
||
| 67 | $k = $j; |
||
| 68 | } |
||
| 69 | break; |
||
| 70 | } |
||
| 71 | break; |
||
| 72 | } |
||
| 73 | if ($concatenating && $value[0] !== T_COMMENT && $value[0] !== T_WHITESPACE) { |
||
| 74 | $concatenating = false; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $functions; |
||
| 79 | } |
||
| 80 | } |
||
| 81 |