Conditions | 10 |
Paths | 8 |
Total Lines | 29 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
74 | * @param int $min Enforce a minimum number of arguments the callable must have |
||
75 | * |
||
76 | * @return mixed |
||
77 | * |
||
78 | * @throws UnresolveableArgument |
||
79 | */ |
||
80 | public function invokeAll(Parameter $parameter, int $min = 0) |
||
81 | { |
||
82 | $arguments = $this->function->getParameters(); |
||
83 | |||
84 | if (\count($arguments) < $min) { |
||
85 | throw new \ArgumentCountError("{$min} argument(s) of type \"{$parameter->type()}\" required."); |
||
86 | } |
||
87 | |||
88 | foreach ($arguments as $key => $argument) { |
||
89 | try { |
||
90 | $arguments[$key] = $parameter->resolve($argument); |
||
91 | } catch (UnresolveableArgument $e) { |
||
92 | throw new UnresolveableArgument(\sprintf('Unable to resolve argument %d for callback. Expected type: "%s"', $key + 1, $parameter->type()), $e); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | return $this->function->invoke(...$arguments); |
||
97 | } |
||
98 | } |
||
99 |