| Conditions | 7 |
| Paths | 12 |
| Total Lines | 59 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 45 | public function parse(array $tokens) |
||
| 46 | { |
||
| 47 | |||
| 48 | $classes = array(); |
||
| 49 | $functions = array(); |
||
| 50 | $anotherTokens = array(); |
||
| 51 | |||
| 52 | // store initial values |
||
| 53 | $isAbstract = false; |
||
| 54 | |||
| 55 | // we group tokens by class |
||
| 56 | $len = sizeof($tokens); |
||
| 57 | for ($i = 0; $i < $len; $i++) { |
||
| 58 | $token = $tokens[$i]; |
||
| 59 | |||
| 60 | if (Token::T_ABSTRACT === $token) { |
||
| 61 | $isAbstract = true; |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | if (Token::T_CLASS === $token || Token::T_INTERFACE === $token) { |
||
| 66 | $classStart = $i; |
||
| 67 | $classEnd = $this->searcher->getPositionOfClosingBrace($tokens, $i); |
||
|
|
|||
| 68 | // we need to start tokens from previous token because of php7 anonymous classes |
||
| 69 | // example: "new class{" |
||
| 70 | $tokensOfClass = array_slice($tokens, max(0, $classStart - 1), ($classEnd - $classStart) + 1); |
||
| 71 | |||
| 72 | $parser = new ClassParser($this->searcher, $this->namespaceResolver); |
||
| 73 | $class = $parser->parse($tokensOfClass); |
||
| 74 | $class->setIsAbstract($isAbstract); |
||
| 75 | array_push($classes, $class); |
||
| 76 | |||
| 77 | $i = $classEnd; |
||
| 78 | $isAbstract = false; |
||
| 79 | continue; |
||
| 80 | } |
||
| 81 | array_push($anotherTokens, $tokens[$i]); |
||
| 82 | } |
||
| 83 | |||
| 84 | // another code (functions, direct calls... |
||
| 85 | $len = sizeof($anotherTokens); |
||
| 86 | for ($i = 0; $i < $len; $i++) { |
||
| 87 | $token = $anotherTokens[$i]; |
||
| 88 | if (Token::T_FUNCTION === $token) { |
||
| 89 | $functionStart = $i; |
||
| 90 | $functionEnd = $this->searcher->getPositionOfClosingBrace($anotherTokens, $i); |
||
| 91 | $parser = new MethodParser($this->searcher, $this->namespaceResolver); |
||
| 92 | $function = $parser->parse(array_slice($anotherTokens, $functionStart, ($functionEnd - $functionStart) + 1)); |
||
| 93 | array_push($functions, $function); |
||
| 94 | |||
| 95 | continue; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $result = new Result; |
||
| 100 | $result->setClasses($classes)->setFunctions($functions); |
||
| 101 | |||
| 102 | return $result; |
||
| 103 | } |
||
| 104 | } |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.