| Conditions | 10 |
| Paths | 9 |
| Total Lines | 50 |
| Code Lines | 24 |
| 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 |
||
| 47 | private function prepareActualParameters(array $formalParameters, array $parameters): array |
||
| 48 | { |
||
| 49 | $result = []; |
||
| 50 | |||
| 51 | // Handle named parameters |
||
| 52 | if ($this->isNamedParameters($parameters)) { |
||
| 53 | |||
| 54 | foreach ($formalParameters as $formalParameter) { |
||
| 55 | /** @var \ReflectionParameter $formalParameter */ |
||
| 56 | |||
| 57 | $formalType = (string) $formalParameter->getType(); |
||
| 58 | $name = $formalParameter->getName(); |
||
|
|
|||
| 59 | |||
| 60 | if ($formalParameter->isOptional()) { |
||
| 61 | if (array_key_exists($name, $parameters)) { |
||
| 62 | $result[$name] = $this->matchType($formalType, $parameters[$name]); |
||
| 63 | } else { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (!array_key_exists($name, $parameters)) { |
||
| 69 | throw new InvalidParamsException('Named parameter error'); |
||
| 70 | } |
||
| 71 | |||
| 72 | $result[$name] = $this->matchType($formalType, $parameters[$name]); |
||
| 73 | } |
||
| 74 | |||
| 75 | return $result; |
||
| 76 | } |
||
| 77 | |||
| 78 | // Handle positional parameters |
||
| 79 | for ($position = 0; $position < count($formalParameters); $position++) { |
||
| 80 | /** @var \ReflectionParameter $formalParameter */ |
||
| 81 | $formalParameter = $formalParameters[$position]; |
||
| 82 | |||
| 83 | if ($formalParameter->isOptional() && !isset($parameters[$position])) { |
||
| 84 | break; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!isset($parameters[$position])) { |
||
| 88 | throw new InvalidParamsException('Positional parameter error'); |
||
| 89 | } |
||
| 90 | |||
| 91 | $formalType = (string) $formalParameter->getType(); |
||
| 92 | $result[] = $this->matchType($formalType, $parameters[$position]); |
||
| 93 | } |
||
| 94 | |||
| 95 | return $result; |
||
| 96 | } |
||
| 97 | |||
| 157 |