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 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 23
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B call() 0 20 5
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: sgoetz
5
 * Date: 15.08.14
6
 * Time: 15:17
7
 */
8
namespace Onigoetz\Imagecache;
9
10
use ReflectionMethod;
11
12
class MethodCaller
13
{
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