Conditions | 10 |
Paths | 17 |
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 | /** @var LNumber|DNumber|String_ $scalar */ |
||
58 | $scalar = $node; |
||
59 | if ($this->hasSign($scalar)) { |
||
60 | $node = $scalar->getAttribute('parent'); |
||
61 | if ($this->isMinus($node)) { |
||
62 | $scalar->value = -$scalar->value; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if ($this->isNumber($scalar) || $this->isString($scalar)) { |
||
67 | |||
68 | if ($this->checkNameContainsLanguage( |
||
69 | $scalar->getAttribute('parent')->var->name ?? '', |
||
70 | $scalar->value |
||
71 | )) { |
||
72 | $this->fileReport->addEntry($node->getLine(), $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: