DefaultValueResolver::resolve()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 5
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 6
rs 9.2222
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
22
/**
23
 * Gets the default value defined in the action signature when no value has been given.
24
 *
25
 * @author Divine Niiquaye Ibok <[email protected]>
26
 */
27
final class DefaultValueResolver implements ArgumentValueResolverInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 16
    public function resolve(\ReflectionParameter $parameter, array $providedParameters)
33
    {
34
35 16
        if ($parameter->isOptional() || $parameter->isDefaultValueAvailable() || $parameter->allowsNull()) {
36
            try {
37 13
                $default = $parameter->getDefaultValue();
38
39 9
                return null !== $default ? $default : __CLASS__;
40 10
            } catch (\ReflectionException $e) {
41
                // Can't get default values from PHP internal classes and functions
42
            }
43
        }
44 14
    }
45
}
46