| Conditions | 15 |
| Paths | 257 |
| Total Lines | 46 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 81 | public function build(string $id, Resolver $resolver) |
||
| 82 | { |
||
| 83 | $builder = $resolver->getBuilder(); |
||
| 84 | |||
| 85 | if ($this->abstract) { |
||
| 86 | throw new ContainerResolutionException(\sprintf('Resolving an abstract definition %s is not allowed.', $id)); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!empty($this->deprecation)) { |
||
| 90 | $deprecation = $this->triggerDeprecation($id, $builder); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (\is_array($value = $this->value)) { |
||
| 94 | $value = $resolver->resolveArguments($value); |
||
| 95 | } |
||
| 96 | |||
| 97 | if (null === $builder) { |
||
| 98 | return !\is_array($value) && $this->lazy ? $resolver->resolve($value) : $value; |
||
| 99 | } |
||
| 100 | |||
| 101 | $defNode = $builder->method($resolver->createMethod($id))->makeProtected(); |
||
| 102 | |||
| 103 | if ($value instanceof \PhpParser\Node) { |
||
| 104 | if ($value instanceof Expr\Array_) { |
||
| 105 | $defNode->setReturnType('array'); |
||
| 106 | } elseif ($value instanceof Expr\New_) { |
||
| 107 | $defNode->setReturnType($value->class->toString()); |
||
| 108 | } |
||
| 109 | } elseif (\PHP_MAJOR_VERSION >= 8) { |
||
| 110 | $defNode->setReturnType('mixed'); |
||
| 111 | } |
||
| 112 | |||
| 113 | if (isset($deprecation)) { |
||
| 114 | $defNode->addStmt($deprecation); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($this->lazy) { |
||
| 118 | $lazyMethod = \is_array($value) ? 'resolveArguments' : 'resolve'; |
||
| 119 | $createdValue = $builder->methodCall($builder->propertyFetch($builder->var('this'), 'resolver'), $lazyMethod, [$value]); |
||
| 120 | } |
||
| 121 | |||
| 122 | if ($this->shared) { |
||
| 123 | $createdValue = $this->triggerSharedBuild($id, $createdValue ?? $builder->val($value), $builder); |
||
| 124 | } |
||
| 125 | |||
| 126 | return $defNode->addStmt(new Return_($createdValue ?? $builder->val($value))); |
||
| 127 | } |
||
| 129 |