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