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

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