| Conditions | 20 |
| Paths | 35 |
| Total Lines | 73 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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 |
||
| 24 | public function getFunctions() |
||
| 25 | { |
||
| 26 | $count = count($this->tokens); |
||
| 27 | $bufferFunctions = array(); |
||
| 28 | /* @var ParsedFunction[] $bufferFunctions */ |
||
| 29 | $functions = array(); |
||
| 30 | /* @var ParsedFunction[] $functions */ |
||
| 31 | |||
| 32 | for ($k = 0; $k < $count; ++$k) { |
||
| 33 | $value = $this->tokens[$k]; |
||
| 34 | |||
| 35 | if (is_string($value)) { |
||
| 36 | $s = $value; |
||
|
|
|||
| 37 | } else { |
||
| 38 | $s = token_name($value[0]).' >'.$value[1].'<'; |
||
| 39 | } |
||
| 40 | |||
| 41 | if (is_string($value)) { |
||
| 42 | if (isset($bufferFunctions[0])) { |
||
| 43 | switch ($value) { |
||
| 44 | case ',': |
||
| 45 | $bufferFunctions[0]->nextArgument(); |
||
| 46 | break; |
||
| 47 | case ')': |
||
| 48 | $functions[] = array_shift($bufferFunctions)->close(); |
||
| 49 | break; |
||
| 50 | case '.': |
||
| 51 | break; |
||
| 52 | default: |
||
| 53 | $bufferFunctions[0]->stopArgument(); |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | |||
| 60 | switch ($value[0]) { |
||
| 61 | case T_CONSTANT_ENCAPSED_STRING: |
||
| 62 | //add an argument to the current function |
||
| 63 | if (isset($bufferFunctions[0])) { |
||
| 64 | $bufferFunctions[0]->addArgumentChunk(PhpCode::convertString($value[1])); |
||
| 65 | } |
||
| 66 | break; |
||
| 67 | case T_STRING: |
||
| 68 | if (isset($bufferFunctions[0])) { |
||
| 69 | $bufferFunctions[0]->stopArgument(); |
||
| 70 | } |
||
| 71 | //new function found |
||
| 72 | for ($j = $k + 1; $j < $count; ++$j) { |
||
| 73 | $nextToken = $this->tokens[$j]; |
||
| 74 | if (is_array($nextToken) && ($nextToken[0] === T_COMMENT || $nextToken[0] === T_WHITESPACE)) { |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | if ($nextToken === '(') { |
||
| 78 | array_unshift($bufferFunctions, new ParsedFunction($value[1], $value[2])); |
||
| 79 | $k = $j; |
||
| 80 | } |
||
| 81 | break; |
||
| 82 | } |
||
| 83 | break; |
||
| 84 | case T_WHITESPACE: |
||
| 85 | case T_COMMENT: |
||
| 86 | break; |
||
| 87 | default: |
||
| 88 | if (isset($bufferFunctions[0])) { |
||
| 89 | $bufferFunctions[0]->stopArgument(); |
||
| 90 | } |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | return $functions; |
||
| 96 | } |
||
| 97 | } |
||
| 98 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.