Completed
Push — master ( 439717...c5d58c )
by Tobias
01:56
created

ContainerAwareTrans::enterNode()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 8.9137
c 0
b 0
f 0
cc 6
nc 5
nop 1
crap 6
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\Php\Symfony;
13
14
use PhpParser\Node;
15
use PhpParser\NodeVisitor;
16
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class ContainerAwareTrans extends BasePHPVisitor implements NodeVisitor
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 4
    public function beforeTraverse(array $nodes): ?Node
27
    {
28 4
        return null;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 4
    public function enterNode(Node $node): ?Node
35
    {
36 4
        if (!$node instanceof Node\Expr\MethodCall) {
37 4
            return null;
38
        }
39
40 4
        if (!\is_string($node->name) && !$node->name instanceof Node\Identifier) {
41 1
            return null;
42
        }
43 4
        $name = (string) $node->name;
44
45
        //If $this->get('translator')->trans('foobar')
46 4
        if ('trans' === $name) {
47 4
            $label = $this->getStringArgument($node, 0);
48 4
            if (null === $label) {
49 4
                return null;
50
            }
51 4
            $domain = $this->getStringArgument($node, 2);
52
53 4
            $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);
54
        }
55
56 4
        return null;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 4
    public function leaveNode(Node $node): ?Node
63
    {
64 4
        return null;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 4
    public function afterTraverse(array $nodes): ?Node
71
    {
72 4
        return null;
73
    }
74
}
75