Passed
Push — master ( 2e3594...a83f63 )
by Emanuele
03:00 queued 14s
created

FeatureNode::createExpression()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
rs 9.2
c 0
b 0
f 0
cc 2
eloc 15
nc 1
nop 3
crap 2.0023
1
<?php
2
3
namespace Ae\FeatureBundle\Twig\Node;
4
5
use Ae\FeatureBundle\Twig\Extension\FeatureExtension;
6
use Twig_Environment;
7
use Twig_Node;
8
use Twig_Node_Expression_Array;
9
use Twig_Node_Expression_Constant;
10
use Twig_Node_Expression_ExtensionReference;
11
use Twig_Node_Expression_MethodCall;
12
use Twig_Node_If;
13
14
/**
15
 * @author Carlo Forghieri <[email protected]>
16
 */
17
class FeatureNode extends Twig_Node_If
18
{
19 3
    public function __construct($name, $parent, $body, $else, $lineno, $tag = null)
20
    {
21 3
        $tests = new Twig_Node([
22 3
            $this->createExpression($name, $parent, $lineno),
23 3
            $body,
24
        ]);
25
26 3
        parent::__construct($tests, $else, $lineno, $tag);
27 3
    }
28
29 3
    protected function createExpression($name, $parent, $lineno)
30
    {
31 3
        return new Twig_Node_Expression_MethodCall(
32 3
            new Twig_Node_Expression_ExtensionReference(
33 3
                version_compare(Twig_Environment::VERSION, '1.26.0', '>=')
34
                    ? FeatureExtension::class
35 3
                    : 'feature',
36
                $lineno
37
            ),
38 3
            'isGranted',
39 3
            new Twig_Node_Expression_Array(
40
                [
41 3
                    new Twig_Node_Expression_Constant('name', $lineno),
42 3
                    new Twig_Node_Expression_Constant($name, $lineno),
43 3
                    new Twig_Node_Expression_Constant('parent', $lineno),
44 3
                    new Twig_Node_Expression_Constant($parent, $lineno),
45
                ],
46
                $lineno
47
            ),
48
            $lineno
49
        );
50
    }
51
}
52