Conditions | 5 |
Paths | 5 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
14 | 57 | public function call($object, $method, $args) |
|
15 | { |
||
16 | 57 | if (!method_exists($object, $method)) { |
|
17 | 3 | throw new \LogicException("Method '$method' doesn't exist"); |
|
18 | } |
||
19 | |||
20 | 54 | $reflected = new ReflectionMethod(get_class($object), $method); |
|
21 | 54 | $parameters = $reflected->getParameters(); |
|
22 | |||
23 | 54 | $arguments = []; |
|
24 | 54 | foreach ($parameters as $param) { |
|
25 | 54 | if (array_key_exists($param->name, $args)) { |
|
26 | 51 | $arguments[$param->name] = $args[$param->name]; |
|
27 | 17 | } else { |
|
28 | 32 | $arguments[$param->name] = ($param->isOptional()) ? $param->getDefaultValue() : null; |
|
29 | } |
||
30 | 18 | } |
|
31 | |||
32 | 54 | return call_user_func_array([$object, $method], $arguments); |
|
33 | } |
||
34 | } |
||
35 |