| Conditions | 12 |
| Paths | 11 |
| Total Lines | 53 |
| Code Lines | 26 |
| 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 |
||
| 70 | private function prepareActualParameters(array $formalParameters, array $parameters): array |
||
| 71 | { |
||
| 72 | $result = []; |
||
| 73 | |||
| 74 | // Handle named parameters |
||
| 75 | if ($this->isNamedArray($parameters)) { |
||
| 76 | |||
| 77 | foreach ($formalParameters as $formalParameter) { |
||
| 78 | /** @var \ReflectionParameter $formalParameter */ |
||
| 79 | |||
| 80 | $formalType = (string) $formalParameter->getType(); |
||
| 81 | $name = $formalParameter->name; |
||
| 82 | |||
| 83 | if ($formalParameter->isOptional()) { |
||
| 84 | if (!array_key_exists($name, $parameters)) { |
||
| 85 | continue; |
||
| 86 | } |
||
| 87 | |||
| 88 | $result[$name] = $formalParameter->getClass() !== null |
||
| 89 | ? $this->toObject($formalParameter->getClass()->name, $parameters[$name]) |
||
| 90 | : $this->matchType($formalType, $parameters[$name]); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (!array_key_exists($name, $parameters)) { |
||
| 94 | throw new InvalidParamsException('Named parameter error'); |
||
| 95 | } |
||
| 96 | |||
| 97 | $result[$name] = $this->matchType($formalType, $parameters[$name]); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $result; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Handle positional parameters |
||
| 104 | foreach ($formalParameters as $position => $formalParameter) { |
||
| 105 | /** @var \ReflectionParameter $formalParameter */ |
||
| 106 | |||
| 107 | if ($formalParameter->isOptional() && !isset($parameters[$position])) { |
||
| 108 | break; |
||
| 109 | } |
||
| 110 | |||
| 111 | if (!isset($parameters[$position])) { |
||
| 112 | throw new InvalidParamsException('Positional parameter error'); |
||
| 113 | } |
||
| 114 | |||
| 115 | $formalType = (string) $formalParameter->getType(); |
||
| 116 | $result[] = $formalParameter->getClass() !== null |
||
| 117 | ? $this->toObject($formalParameter->getClass()->name, $parameters[$position]) |
||
| 118 | : $this->matchType($formalType, $parameters[$position]); |
||
| 119 | } |
||
| 120 | |||
| 121 | return $result; |
||
| 122 | } |
||
| 123 | |||
| 218 |