Completed
Push — master ( 236a45...b262d2 )
by Yaroslav
09:39
created

SymfonySecurityResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 9 3
A supports() 0 3 1
A __construct() 0 3 1
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\Security\TestResolver;
12
13
use Yarhon\RouteGuardBundle\Security\Test\TestInterface;
14
use Yarhon\RouteGuardBundle\Routing\RouteContextInterface;
15
use Yarhon\RouteGuardBundle\Exception\RuntimeException;
16
17
/**
18
 * @author Yaroslav Honcharuk <[email protected]>
19
 */
20
class SymfonySecurityResolver implements SymfonySecurityResolverInterface
21
{
22
    /**
23
     * @var \Traversable|SymfonySecurityResolverInterface[]
24
     */
25
    private $resolvers;
26
27
    /**
28
     * @param \Traversable|SymfonySecurityResolverInterface[] $resolvers
29
     */
30 21
    public function __construct($resolvers = [])
31
    {
32 21
        $this->resolvers = $resolvers;
33 21
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function supports(TestInterface $test)
39
    {
40 1
        return true;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 15
    public function resolve(TestInterface $test, RouteContextInterface $routeContext)
47
    {
48 15
        foreach ($this->resolvers as $resolver) {
49 15
            if ($resolver->supports($test)) {
50 15
                return $resolver->resolve($test, $routeContext);
51
            }
52
        }
53
54 1
        throw new RuntimeException(sprintf('No resolver exists for test instance of "%s".', get_class($test)));
55
    }
56
}
57