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

FeatureExtension::getTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
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
    /**
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