DefaultResolver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 2
1
<?php
2
3
namespace mindplay\unravel\resolvers;
4
5
use mindplay\unravel\Resolver;
6
use ReflectionParameter;
7
8
/**
9
 * Resolves with the default argument value, if the given parameter has a default value.
10
 *
11
 * Note that the argument does not have to be optional, as in:
12
 *
13
 *     function ($foo = 1, $bar) { ... }
14
 *
15
 * In this case, `$foo` does have a default, and will be resolved as `1`, even though
16
 * the parameter isn't optional. (in most cases, of course, parameters with default
17
 * values will also be optional.)
18
 */
19
class DefaultResolver implements Resolver
20
{
21 1
    public function resolve(ReflectionParameter $param, $next)
22
    {
23 1
        if ($param->isDefaultValueAvailable()) {
24 1
            return $param->getDefaultValue();
25
        }
26
27 1
        return $next($param);
28
    }
29
}
30