Invoker   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 28
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B invoke() 0 25 4
1
<?php
2
3
namespace mindplay\walkway;
4
5
use Closure;
6
use ReflectionFunction;
7
8
/**
9
 * This is the default invoker implementation, which is only capable of resolving
10
 * parameters directly provided.
11
 */
12
class Invoker implements InvokerInterface
13
{
14 1
    public function invoke(Closure $func, array $params)
15
    {
16 1
        $func_ref = new ReflectionFunction($func);
17 1
        $param_refs = $func_ref->getParameters();
18
19 1
        $args = array();
20
21 1
        foreach ($param_refs as $param_ref) {
22 1
            if (array_key_exists($param_ref->name, $params)) {
23 1
                $args[] = $params[$param_ref->name];
24
25 1
                continue;
26
            }
27
28 1
            if ($param_ref->isDefaultValueAvailable()) {
29 1
                $args[] = $param_ref->getDefaultValue();
30
31 1
                continue;
32
            }
33
34 1
            throw new InvocationException("missing parameter: \${$param_ref->name}", $func);
35 1
        }
36
37 1
        return call_user_func_array($func, $args);
38
    }
39
}
40