| Conditions | 10 |
| Paths | 15 |
| Total Lines | 43 |
| 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 |
||
| 44 | public function enterNode(Node $node): ?int |
||
| 45 | { |
||
| 46 | if ($this->isIgnoreableConst($node)) { |
||
| 47 | if ($this->checkNameContainsLanguage( |
||
| 48 | $node->name->name, |
||
|
|
|||
| 49 | $node->value->value ?? 0 |
||
| 50 | )) { |
||
| 51 | $this->fileReport->addEntry($node->getLine(), $node->value->value); |
||
| 52 | } |
||
| 53 | |||
| 54 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
||
| 55 | } |
||
| 56 | |||
| 57 | |||
| 58 | if ($this->isNumber($node) || $this->isString($node)) { |
||
| 59 | /** @var LNumber|DNumber|String_ $scalar */ |
||
| 60 | $scalar = $node; |
||
| 61 | |||
| 62 | if ($this->checkNameContainsLanguage( |
||
| 63 | $node->getAttribute('parent')->var->name ?? '', |
||
| 64 | $node->value |
||
| 65 | )) { |
||
| 66 | $this->fileReport->addEntry($node->getLine(), $scalar->value); |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($this->hasSign($node)) { |
||
| 70 | $node = $node->getAttribute('parent'); |
||
| 71 | if ($this->isMinus($node)) { |
||
| 72 | $scalar->value = -$scalar->value; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | foreach ($this->option->getExtensions() as $extension) { |
||
| 76 | $extension->setOption($this->option); |
||
| 77 | if ($extension->extend($node)) { |
||
| 78 | $this->fileReport->addEntry($scalar->getLine(), $scalar->value); |
||
| 79 | |||
| 80 | return null; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return null; |
||
| 86 | } |
||
| 87 | |||
| 165 |
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: