DelegatingAuthorizationChecker::isGranted()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
cc 3
nc 3
nop 2
crap 3
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 21
    public function __construct($checkers = [])
31
    {
32 21
        $this->checkers = $checkers;
33 21
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 15
    public function isGranted(TestInterface $test, RouteContextInterface $routeContext)
39
    {
40 15
        foreach ($this->checkers as $checker) {
41 15
            if ($checker->supports($test)) {
42 14
                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