RouteAuthorizationChecker   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 38
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isGranted() 0 11 3
A __construct() 0 4 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;
12
13
use Psr\Log\LoggerAwareInterface;
14
use Psr\Log\LoggerAwareTrait;
15
use Yarhon\RouteGuardBundle\Security\AuthorizationChecker\AuthorizationCheckerInterface;
16
use Yarhon\RouteGuardBundle\Routing\RouteContextInterface;
17
18
/**
19
 * @author Yaroslav Honcharuk <[email protected]>
20
 */
21
class RouteAuthorizationChecker implements RouteAuthorizationCheckerInterface, LoggerAwareInterface
22
{
23
    use LoggerAwareTrait;
24
25
    /**
26
     * @var TestLoaderInterface
27
     */
28
    private $testLoader;
29
30
    /**
31
     * @var AuthorizationCheckerInterface
32
     */
33
    private $authorizationChecker;
34
35
    /**
36
     * @param TestLoaderInterface           $testLoader
37
     * @param AuthorizationCheckerInterface $authorizationChecker
38
     */
39 21
    public function __construct(TestLoaderInterface $testLoader, AuthorizationCheckerInterface $authorizationChecker)
40
    {
41 21
        $this->testLoader = $testLoader;
42 21
        $this->authorizationChecker = $authorizationChecker;
43 21
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 21
    public function isGranted(RouteContextInterface $routeContext)
49
    {
50 21
        $tests = $this->testLoader->load($routeContext);
51
52 21
        foreach ($tests as $test) {
53 16
            if (!$this->authorizationChecker->isGranted($test, $routeContext)) {
54 10
                return false;
55
            }
56
        }
57
58 11
        return true;
59
    }
60
}
61