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

TwigVisitor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 26
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A doEnterNode() 0 12 2
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