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