| Conditions | 16 |
| Paths | 17 |
| Total Lines | 45 |
| Code Lines | 25 |
| 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 |
||
| 100 | private function resolveParameters(array $refParameters, array $arguments): array |
||
| 101 | { |
||
| 102 | $parameters = []; |
||
| 103 | |||
| 104 | foreach ($refParameters as $index => $parameter) { |
||
| 105 | $typeHint = $parameter->getType(); |
||
| 106 | |||
| 107 | if ($typeHint instanceof \ReflectionUnionType) { |
||
| 108 | foreach ($typeHint->getTypes() as $unionType) { |
||
| 109 | if (isset($arguments[$unionType->getName()])) { |
||
| 110 | $parameters[$index] = $arguments[$unionType->getName()]; |
||
| 111 | |||
| 112 | continue 2; |
||
| 113 | } |
||
| 114 | |||
| 115 | if (null !== $this->container && $this->container->has($unionType->getName())) { |
||
| 116 | $parameters[$index] = $this->container->get($unionType->getName()); |
||
| 117 | |||
| 118 | continue 2; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } elseif ($typeHint instanceof \ReflectionNamedType) { |
||
| 122 | if (isset($arguments[$typeHint->getName()])) { |
||
| 123 | $parameters[$index] = $arguments[$typeHint->getName()]; |
||
| 124 | |||
| 125 | continue; |
||
| 126 | } |
||
| 127 | |||
| 128 | if (null !== $this->container && $this->container->has($typeHint->getName())) { |
||
| 129 | $parameters[$index] = $this->container->get($typeHint->getName()); |
||
| 130 | |||
| 131 | continue; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if (isset($arguments[$parameter->getName()])) { |
||
| 136 | $parameters[$index] = $arguments[$parameter->getName()]; |
||
| 137 | } elseif (null !== $this->container && $this->container->has($parameter->getName())) { |
||
| 138 | $parameters[$index] = $this->container->get($parameter->getName()); |
||
| 139 | } elseif ($parameter->allowsNull() && !$parameter->isDefaultValueAvailable()) { |
||
| 140 | $parameters[$index] = null; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | return $parameters; |
||
| 145 | } |
||
| 147 |