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

DefaultValueResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
ccs 5
cts 5
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 8 5
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