SessionValueResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 25
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A supports() 0 12 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\HttpFoundation\Session\SessionInterface;
14
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
15
16
/**
17
 * Returns the Session.
18
 *
19
 * @author Yaroslav Honcharuk <[email protected]>
20
 * @author Iltar van der Berg <[email protected]>
21
 */
22
final class SessionValueResolver implements ArgumentValueResolverInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 8
    public function supports(ArgumentResolverContextInterface $context, ArgumentMetadata $argument)
28
    {
29 8
        if (!$context->getRequest()->hasSession()) {
30 4
            return false;
31
        }
32
33 4
        $type = $argument->getType();
34 4
        if (SessionInterface::class !== $type && !is_subclass_of($type, SessionInterface::class)) {
35 1
            return false;
36
        }
37
38 3
        return $context->getRequest()->getSession() instanceof $type;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function resolve(ArgumentResolverContextInterface $context, ArgumentMetadata $argument)
45
    {
46 1
        return $context->getRequest()->getSession();
47
    }
48
}
49