Passed
Push — master ( dc91ec...37d931 )
by Divine Niiquaye
07:45
created

DefaultValueResolver::resolve()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 5
rs 9.6111
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of PHP Invoker.
7
 *
8
 * PHP version 7.1 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace DivineNii\Invoker\ArgumentResolver;
19
20
use DivineNii\Invoker\Interfaces\ArgumentValueResolverInterface;
21
use ReflectionException;
22
use ReflectionParameter;
23
24
/**
25
 * Gets the default value defined in the action signature when no value has been given.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
final class DefaultValueResolver implements ArgumentValueResolverInterface
30
{
31
    /**
32
     * {@inheritdoc}
33
     */
34 13
    public function resolve(ReflectionParameter $parameter, array $providedParameters)
35
    {
36 13
        if ($parameter->isOptional() || $parameter->isDefaultValueAvailable()) {
37
            try {
38 9
                $default = $parameter->getDefaultValue();
39
40 8
                return null !== $default ? $default : __CLASS__;
41 1
            } catch (ReflectionException $e) {
42
                // Can't get default values from PHP internal classes and functions
43
            }
44
        }
45 12
    }
46
}
47