FeatureExtension::isGranted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Ae\FeatureBundle\Twig\Extension;
4
5
use Ae\FeatureBundle\Service\Feature;
6
use Ae\FeatureBundle\Twig\TokenParser\FeatureTokenParser;
7
use Twig_Extension;
8
use Twig_SimpleTest;
9
10
/**
11
 * @author Carlo Forghieri <[email protected]>
12
 */
13
class FeatureExtension extends Twig_Extension
14
{
15
    /**
16
     * @var Feature
17
     */
18
    protected $service;
19
20
    public function __construct(Feature $service)
21
    {
22
        $this->service = $service;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function getTokenParsers()
29
    {
30
        return [
31
            new FeatureTokenParser(),
32
        ];
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getTests()
39
    {
40
        return [
41
            new Twig_SimpleTest('granted feature', function (array $arguments) {
42
                return $this->isGranted(...$arguments);
43
            }),
44
        ];
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getName()
51
    {
52
        return 'feature';
53
    }
54
55
    /**
56
     * @param string $name
57
     * @param string $parent
58
     *
59
     * @return bool
60
     */
61
    public function isGranted($name, $parent)
62
    {
63
        return $this->service->isGranted($name, $parent);
64
    }
65
}
66