Conditions | 11 |
Paths | 52 |
Total Lines | 36 |
Code Lines | 20 |
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 |
||
80 | public function build(string $id, Resolver $resolver) |
||
81 | { |
||
82 | if (null === $builder = $resolver->getBuilder()) { |
||
83 | if ($this->isDeprecated()) { |
||
84 | $this->triggerDeprecation($id); |
||
85 | } |
||
86 | |||
87 | return \is_array($value = $this->value) ? $resolver->resolveArguments($value) : $value; |
||
88 | } |
||
89 | |||
90 | $defNode = $builder->method($resolver->createMethod($id))->makeProtected(); |
||
91 | |||
92 | if ($this->value instanceof \PhpParser\Node) { |
||
93 | if ($this->value instanceof Expr\Array_) { |
||
94 | $defNode->setReturnType('array'); |
||
95 | } elseif ($this->value instanceof Expr\New_) { |
||
96 | $defNode->setReturnType($this->value->class->toString()); |
||
97 | } |
||
98 | } else { |
||
99 | $defNode->setReturnType(\get_debug_type($this->value)); |
||
100 | } |
||
101 | |||
102 | if ($this->isDeprecated()) { |
||
103 | $defNode->addStmt($this->triggerDeprecation($id, $builder)); |
||
104 | } |
||
105 | |||
106 | if ($this->lazy) { |
||
107 | $lazyMethod = \is_array($this->value) ? 'resolveArguments' : 'resolve'; |
||
108 | $createdValue = $builder->methodCall($builder->propertyFetch($builder->var('this'), 'resolver'), $lazyMethod, [$this->value]); |
||
109 | } |
||
110 | |||
111 | if ($this->shared) { |
||
112 | $createdValue = $this->triggerSharedBuild($id, $createdValue ?? $builder->val($this->value), $builder); |
||
113 | } |
||
114 | |||
115 | return $defNode->addStmt(new Return_($createdValue ?? $builder->val($this->value))); |
||
116 | } |
||
118 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.