DefaultResolver::resolve()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 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