Completed
Push — master ( 82fc51...fcdb0d )
by Tobias
03:20
created

TwigVisitor::doEnterNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 5
cp 0.8
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
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\Node\Node;
16
17
/**
18
 * Factory class and base class for TwigVisitor.
19
 *
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
abstract class TwigVisitor extends BaseVisitor
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 5
    protected function doEnterNode(Node $node): Node
36
    {
37
        // If not initialized
38 5
        if (null === $this->collection) {
39
            // We have not executed BaseVisitor::init which means that we are not currently extracting
40
            return $node;
41
        }
42
43
        return $this->worker->work($node, $this->collection, function () {
44 5
            return $this->getAbsoluteFilePath();
45 5
        });
46
    }
47
}
48