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

Feature   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A isGranted() 0 10 2
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