| Conditions | 10 |
| Paths | 6 |
| Total Lines | 45 |
| Code Lines | 27 |
| 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 | $simpleDoubleQuote = array( |
||
|
|
|||
| 74 | 'n' => "\n", |
||
| 75 | 'r' => "\r", |
||
| 76 | 't' => "\t", |
||
| 77 | 'v' => "\v", |
||
| 78 | 'e' => "\f", |
||
| 79 | '\\' => '\\', |
||
| 80 | '$' => '$', |
||
| 81 | '"' => '"', |
||
| 82 | ); |
||
| 83 | |||
| 84 | for ($k = 0; $k < $count; ++$k) { |
||
| 85 | $value = $this->tokens[$k]; |
||
| 86 | |||
| 87 | //close the current function |
||
| 88 | if (is_string($value)) { |
||
| 89 | if ($value === ')' && isset($bufferFunctions[0])) { |
||
| 90 | $functions[] = array_shift($bufferFunctions); |
||
| 91 | } |
||
| 92 | |||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | //add an argument to the current function |
||
| 97 | if (isset($bufferFunctions[0]) && ($value[0] === T_CONSTANT_ENCAPSED_STRING)) { |
||
| 98 | $bufferFunctions[0][2][] = static::decodeString($value[1]); |
||
| 99 | continue; |
||
| 100 | } |
||
| 101 | |||
| 102 | //new function found |
||
| 103 | if (($value[0] === T_STRING) && is_string($this->tokens[$k + 1]) && ($this->tokens[$k + 1] === '(')) { |
||
| 104 | array_unshift($bufferFunctions, array($value[1], $value[2], array())); |
||
| 105 | ++$k; |
||
| 106 | |||
| 107 | continue; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | return $functions; |
||
| 112 | } |
||
| 113 | } |
||
| 114 |
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.