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

RbacAuthorizationChecker::isGranted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 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