MethodCaller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B call() 0 20 5
1
<?php
2
3
namespace Onigoetz\Deployer;
4
5
use ReflectionMethod;
6
7
class MethodCaller
8
{
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