FeatureExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 2
b 0
f 0
dl 0
loc 51
ccs 0
cts 12
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getTokenParsers() 0 4 1
A getTests() 0 5 1
A getName() 0 3 1
A isGranted() 0 3 1
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