| Conditions | 21 |
| Paths | 19 |
| Total Lines | 84 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 82 | public function enterNode(Node $node) |
||
| 83 | { |
||
| 84 | // Class statements |
||
| 85 | if ($node instanceof ClassStatement) { |
||
| 86 | // Classes that extend another class |
||
| 87 | if ($node->extends !== null) { |
||
| 88 | $extends = $node->extends->toString(); |
||
| 89 | if ($this->isRenamed($extends)) { |
||
| 90 | $node->extends = new Name($this->getNewName($extends)); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | // Classes that implement an interface |
||
| 95 | if ($node->implements !== null && count($node->implements) > 0) { |
||
| 96 | |||
| 97 | $implements = array(); |
||
| 98 | |||
| 99 | foreach($node->implements as $implementsName) { |
||
| 100 | |||
| 101 | // Old name (as string) |
||
| 102 | $oldName = $implementsName->toString(); |
||
| 103 | |||
| 104 | if ($this->isRenamed($oldName)) { |
||
| 105 | // If renamed, set new one |
||
| 106 | $implements[] = new Name($this->getNewName($oldName)); |
||
| 107 | } else { |
||
| 108 | // If not renamed, pass old one |
||
| 109 | $implements[] = $implementsName; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | $node->implements = $implements; |
||
| 114 | } |
||
| 115 | |||
| 116 | return $node; |
||
| 117 | } |
||
| 118 | |||
| 119 | // Param rename |
||
| 120 | if ($node instanceof Param && $node->type instanceof Name) { |
||
| 121 | |||
| 122 | // Name |
||
| 123 | $name = $node->type->toString(); |
||
| 124 | |||
| 125 | // Has it been renamed? |
||
| 126 | if ($this->isRenamed($name)) { |
||
| 127 | $node->type = $this->getNewName($name); |
||
| 128 | return $node; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | // Static call or constant lookup on class |
||
| 133 | if ( |
||
| 134 | $node instanceof ClassConstFetch |
||
| 135 | || $node instanceof StaticCall |
||
| 136 | || $node instanceof StaticPropertyFetch |
||
| 137 | || $node instanceof StaticVar |
||
| 138 | || $node instanceof NewExpression |
||
| 139 | || $node instanceof InstanceOfExpression |
||
| 140 | ) { |
||
| 141 | |||
| 142 | // We need to be in a class for this to work |
||
| 143 | if (empty($this->classNode)) { |
||
| 144 | return; |
||
| 145 | } |
||
| 146 | |||
| 147 | // We need a name |
||
| 148 | if (!($node->class instanceof Name)) { |
||
| 149 | return; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Class name |
||
| 153 | $name = $node->class->toString(); |
||
| 154 | |||
| 155 | if ($name === $this->classNode->name) { |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | // Has it been renamed? |
||
| 160 | if ($this->isRenamed($name)) { |
||
| 161 | $node->class = new Name($this->getNewName($name)); |
||
| 162 | return $node; |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 247 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: