Completed
Pull Request — master (#41)
by Emanuele
05:27
created

Feature::isGranted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2.2559
1
<?php
2
3
namespace Ae\FeatureBundle\Service;
4
5
use Ae\FeatureBundle\Entity\FeatureManager;
6
use Ae\FeatureBundle\Security\FeatureSecurity;
7
use Exception;
8
9
/**
10
 * @author Carlo Forghieri <[email protected]>
11
 */
12
class Feature
13
{
14
    /**
15
     * @var FeatureManager
16
     */
17
    protected $manager;
18
19
    /**
20
     * @var FeatureSecurity
21
     */
22
    protected $security;
23
24
    /**
25
     * @param FeatureManager  $manager
26
     * @param FeatureSecurity $security
27
     */
28 2
    public function __construct(
29
        FeatureManager $manager,
30
        FeatureSecurity $security
31
    ) {
32 2
        $this->manager = $manager;
33 2
        $this->security = $security;
34 2
    }
35
36
    /**
37
     * Check if a feature (defined by name/parent) is granted to the logged user.
38
     *
39
     * @param string $name
40
     * @param string $parent
41
     *
42
     * @return bool
43
     */
44 2
    public function isGranted($name, $parent)
45
    {
46
        try {
47 2
            return $this->security->isGranted(
48 2
                $this->manager->find($name, $parent)
49
            );
50
        } catch (Exception $exception) {
51
            return false;
52
        }
53
    }
54
}
55