| Conditions | 10 |
| Paths | 99 |
| Total Lines | 80 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 48 | public function parse($tokens) |
||
| 49 | { |
||
| 50 | // anonymous class |
||
| 51 | if (Token::T_NEW === $tokens[0]) { |
||
| 52 | $class = new KlassAnonymous; |
||
| 53 | $class->setName($tokens[2]); |
||
| 54 | } elseif (Token::T_INTERFACE === $tokens[1]) { |
||
| 55 | $class = new KlassInterface(); |
||
| 56 | $class->setName($tokens[2]); |
||
| 57 | } else { |
||
| 58 | $class = new Klass(); |
||
| 59 | $class->setName($tokens[2]); |
||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | $functions = $attributes = array(); |
||
| 64 | $len = sizeof($tokens); |
||
| 65 | |||
| 66 | // default values |
||
| 67 | $isStatic = false; |
||
| 68 | $visibility = Token::T_VISIBILITY_PUBLIC; |
||
| 69 | |||
| 70 | for ($i = 1; $i < $len; $i++) { |
||
| 71 | |||
| 72 | $token = $tokens[$i]; |
||
| 73 | |||
| 74 | // static |
||
| 75 | if (Token::T_STATIC === $token) { |
||
| 76 | $isStatic = true; |
||
| 77 | } |
||
| 78 | |||
| 79 | // visibility |
||
| 80 | if (in_array($token, array(Token::T_VISIBILITY_PRIVATE, Token::T_VISIBILITY_PROTECTED, Token::T_VISIBILITY_PUBLIC))) { |
||
| 81 | $visibility = $token; |
||
| 82 | } |
||
| 83 | |||
| 84 | // method |
||
| 85 | if (Token::T_FUNCTION === $token) { |
||
| 86 | $functionStart = $i; |
||
| 87 | $functionEnd = $this->searcher->getPositionOfClosingBrace($tokens, $i); |
||
|
|
|||
| 88 | $parser = new MethodParser($this->searcher, $this->namespaceResolver); |
||
| 89 | $method = $parser->parse(array_slice($tokens, $functionStart, ($functionEnd - $functionStart) + 1)); |
||
| 90 | |||
| 91 | // attribute external informations |
||
| 92 | $method->setIsStatic($isStatic)->setVisibility($visibility); |
||
| 93 | $isStatic = false; |
||
| 94 | $visibility = Token::T_VISIBILITY_PUBLIC; |
||
| 95 | |||
| 96 | $functions[$method->getName()] = $method; |
||
| 97 | $i = $functionEnd; |
||
| 98 | } |
||
| 99 | |||
| 100 | // attribute |
||
| 101 | if ('$' === $token[0]) { |
||
| 102 | $attribute = new Attribute($token, $visibility, $isStatic); |
||
| 103 | array_push($attributes, $attribute); |
||
| 104 | } |
||
| 105 | |||
| 106 | // extends |
||
| 107 | if (Token::T_EXTENDS === $token) { |
||
| 108 | $brace = $this->searcher->getNext($tokens, $i, Token::T_BRACE_OPEN); |
||
| 109 | $parents = array_slice($tokens, $i + 1, ($brace - $i) - 1); |
||
| 110 | // exclude implements |
||
| 111 | $split = preg_split('!implements!i', implode(',', $parents)); |
||
| 112 | $parents = array_filter(explode(',', $split[0])); |
||
| 113 | foreach ($parents as $p => $name) { |
||
| 114 | $parents[$p] = $this->namespaceResolver->resolve($name); |
||
| 115 | } |
||
| 116 | $class->setParents($parents); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | $class |
||
| 121 | ->setTokens($tokens) |
||
| 122 | ->setMethods($functions) |
||
| 123 | ->setAttributes($attributes) |
||
| 124 | ->setNamespace($this->namespaceResolver->getCurrentNamespace()); |
||
| 125 | |||
| 126 | return $class; |
||
| 127 | } |
||
| 128 | } |
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.