| Conditions | 11 |
| Paths | 17 |
| Total Lines | 42 |
| 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 | /** @var LNumber|DNumber|String_ $scalar */ |
||
| 58 | $scalar = $node; |
||
| 59 | if ($this->hasSign($scalar)) { |
||
| 60 | $node = $scalar->getAttribute('parent'); |
||
| 61 | if ($this->isMinus($node) && isset($scalar->value)) { |
||
| 62 | $scalar->value = -$scalar->value; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($this->isNumber($scalar) || $this->isString($scalar)) { |
||
| 67 | if ($this->checkNameContainsLanguage( |
||
| 68 | $scalar->getAttribute('parent')->var->name ?? '', |
||
| 69 | $scalar->value |
||
| 70 | )) { |
||
| 71 | $this->fileReport->addEntry($node->getLine(), $scalar->value); |
||
| 72 | } |
||
| 73 | |||
| 74 | foreach ($this->option->getExtensions() as $extension) { |
||
| 75 | $extension->setOption($this->option); |
||
| 76 | if ($extension->extend($node)) { |
||
| 77 | $this->fileReport->addEntry($scalar->getLine(), $scalar->value); |
||
| 78 | |||
| 79 | return null; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 164 |
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: