Completed
Push — master ( a423a5...0fdb96 )
by Tobias
03:31
created

TwigVisitor::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
ccs 3
cts 4
cp 0.75
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
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
16
/**
17
 * Factory class and base class for TwigVisitor.
18
 *
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
abstract class TwigVisitor extends BaseVisitor
22
{
23
    /**
24
     * @var Worker
25
     */
26
    private $worker;
27
28
    /**
29
     * @param Worker|null $worker
30
     */
31 4
    public function __construct(Worker $worker = null)
32
    {
33 4
        if (null === $worker) {
34 4
            $worker = new Worker();
35 4
        }
36
37 4
        $this->worker = $worker;
38 4
    }
39
40
    /**
41
     * @return Twig1Visitor|Twig2Visitor
42
     */
43 4
    public static function create()
44
    {
45 4
        if (\Twig_Environment::MAJOR_VERSION === 1) {
46 4
            return new Twig1Visitor();
47
        }
48
49
        return new Twig2Visitor();
50
    }
51
52
    /**
53
     * @param \Twig_Node|\Twig_NodeInterface $node
54
     *
55
     * @return \Twig_Node|\Twig_NodeInterface
56
     */
57
    protected function doEnterNode($node)
58
    {
59 4
        return $this->worker->work($node, $this->collection, function () {
60 4
            return $this->getAbsoluteFilePath();
61 4
        });
62
    }
63
}
64