Completed
Pull Request — master (#63)
by Emanuele
05:47
created

FeatureExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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
    /**
21
     * @param Feature $service
22
     */
23
    public function __construct(Feature $service)
24
    {
25
        $this->service = $service;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getTokenParsers()
32
    {
33
        return [
34
            new FeatureTokenParser(),
35
        ];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getTests()
42
    {
43
        return [
44
            new Twig_SimpleTest('granted feature', function (array $arguments) {
45
                return $this->isGranted(...$arguments);
46
            }),
47
        ];
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getName()
54
    {
55
        return 'feature';
56
    }
57
58
    /**
59
     * @param string $name
60
     * @param string $parent
61
     *
62
     * @return bool
63
     */
64
    public function isGranted($name, $parent)
65
    {
66
        return $this->service->isGranted($name, $parent);
67
    }
68
}
69