Completed
Push — master ( c06770...3231e7 )
by Tobias
01:32
created

TwigVisitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 45
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A enterNode() 0 12 2
A leaveNode() 0 4 1
A getPriority() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Extractor\Visitor\Twig;
13
14
use Translation\Extractor\Visitor\BaseVisitor;
15
use Twig\Environment;
16
use Twig\Node\Node;
17
use Twig\NodeVisitor\NodeVisitorInterface;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
final class TwigVisitor extends BaseVisitor implements NodeVisitorInterface
23
{
24
    private $worker;
25
26 5
    public function __construct(Worker $worker = null)
27
    {
28 5
        if (null === $worker) {
29 5
            $worker = new Worker();
30
        }
31
32 5
        $this->worker = $worker;
33 5
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 5
    public function enterNode(Node $node, Environment $env): Node
39
    {
40
        // If not initialized
41 5
        if (null === $this->collection) {
42
            // We have not executed BaseVisitor::init which means that we are not currently extracting
43
            return $node;
44
        }
45
46
        return $this->worker->work($node, $this->collection, function () {
47 5
            return $this->getAbsoluteFilePath();
48 5
        });
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 5
    public function leaveNode(Node $node, Environment $env): ?Node
55
    {
56 5
        return $node;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 5
    public function getPriority()
63
    {
64 5
        return 0;
65
    }
66
}
67