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

DelegatingAuthorizationChecker::supports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 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