Passed
Pull Request — master (#2)
by Victor
02:42
created

Extension::getTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot;
5
6
use Shoot\Shoot\Twig\NodeVisitor\ModelNodeVisitor;
7
use Shoot\Shoot\Twig\TokenParser\ModelTokenParser;
8
use Shoot\Shoot\Twig\TokenParser\OptionalTokenParser;
9
use Twig_ExtensionInterface as ExtensionInterface;
10
use Twig_Filter as TwigFilter;
11
use Twig_Function as TwigFunction;
12
use Twig_NodeVisitorInterface as NodeVisitorInterface;
13
use Twig_Test as TwigTest;
14
use Twig_TokenParserInterface as TokenParserInterface;
15
16
final class Extension implements ExtensionInterface
17
{
18
    /** @var Pipeline */
19
    private $pipeline;
20
21
    /**
22
     * @param Pipeline $pipeline
23
     */
24 9
    public function __construct(Pipeline $pipeline)
25
    {
26 9
        $this->pipeline = $pipeline;
27 9
    }
28
29
    /**
30
     * @internal This method is used by the compiled Twig templates to access the pipeline. It should not be used
31
     * directly.
32
     *
33
     * @param View $view
34
     *
35
     * @return void
36
     */
37 6
    public function process(View $view)
38
    {
39 6
        $this->pipeline->process($view);
40 5
    }
41
42
    /**
43
     * Returns a list of filters to add to the existing list.
44
     *
45
     * @return TwigFilter[]
46
     */
47
    public function getFilters(): array
48
    {
49
        return [
50 7
            new TwigFilter('variables', function (PresentationModel $presentationModel): array {
51 2
                return $presentationModel->getVariables();
52 7
            }),
53
        ];
54
    }
55
56
    /**
57
     * Returns a list of functions to add to the existing list.
58
     *
59
     * @return TwigFunction[]
60
     */
61 6
    public function getFunctions(): array
62
    {
63 6
        return [];
64
    }
65
66
    /**
67
     * Returns the node visitor instances to add to the existing list.
68
     *
69
     * @return NodeVisitorInterface[]
70
     */
71 6
    public function getNodeVisitors(): array
72
    {
73 6
        return [new ModelNodeVisitor()];
74
    }
75
76
    /**
77
     * Returns a list of operators to add to the existing list.
78
     *
79
     * @return array[] First array of unary operators, second array of binary operators
80
     */
81 6
    public function getOperators(): array
82
    {
83 6
        return [];
84
    }
85
86
    /**
87
     * Returns a list of tests to add to the existing list.
88
     *
89
     * @return TwigTest[]
90
     */
91
    public function getTests(): array
92
    {
93
        return [
94 7
            new TwigTest('model', function ($value): bool {
95 2
                return $value instanceof PresentationModel;
96 7
            }),
97
        ];
98
    }
99
100
    /**
101
     * Returns the token parser instances to add to the existing list.
102
     *
103
     * @return TokenParserInterface[]
104
     */
105 6
    public function getTokenParsers(): array
106
    {
107
        return [
108 6
            new ModelTokenParser(),
109 6
            new OptionalTokenParser(),
110
        ];
111
    }
112
}
113