Completed
Push — master ( d27170...133b57 )
by Kamil
17:22
created

RbacAuthorizationChecker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isGranted() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\RbacBundle\Authorization;
13
14
use Sylius\Bundle\ResourceBundle\Controller\AuthorizationCheckerInterface as ResourceBundleAuthorizationCheckerInterface;
15
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
16
use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface;
17
18
/**
19
 * @author Paweł Jędrzejewski <[email protected]>
20
 */
21
class RbacAuthorizationChecker implements ResourceBundleAuthorizationCheckerInterface
22
{
23
    /**
24
     * @var AuthorizationCheckerInterface
25
     */
26
    private $rbacAuthorizationChecker;
27
28
    /**
29
     * @param AuthorizationCheckerInterface $rbacAuhtorizationChecker
30
     */
31
    public function __construct(AuthorizationCheckerInterface $rbacAuhtorizationChecker)
32
    {
33
        $this->rbacAuthorizationChecker = $rbacAuhtorizationChecker;
34
    }
35
36
    /**
37
     * @param RequestConfiguration $requestConfiguration
38
     * @param string $permission
39
     *
40
     * @return bool
41
     */
42
    public function isGranted(RequestConfiguration $requestConfiguration, $permission)
43
    {
44
        if (!$requestConfiguration->hasPermission()) {
45
            return true;
46
        }
47
48
        return $this->rbacAuthorizationChecker->isGranted($permission);
49
    }
50
}
51