Completed
Branch master (c0d8ef)
by Yaroslav
06:36
created

DefaultValueResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 3
dl 0
loc 16
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 2
A supports() 0 3 4
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Controller\ArgumentResolver;
12
13
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
14
15
/**
16
 * Returns the default value defined in the action signature when no value has been given.
17
 *
18
 * @author Yaroslav Honcharuk <[email protected]>
19
 * @author Iltar van der Berg <[email protected]>
20
 */
21
final class DefaultValueResolver implements ArgumentValueResolverInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 6
    public function supports(ArgumentResolverContextInterface $context, ArgumentMetadata $argument)
27
    {
28 6
        return $argument->hasDefaultValue() || (null !== $argument->getType() && $argument->isNullable() && !$argument->isVariadic());
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 4
    public function resolve(ArgumentResolverContextInterface $context, ArgumentMetadata $argument)
35
    {
36 4
        return $argument->hasDefaultValue() ? $argument->getDefaultValue() : null;
37
    }
38
}
39