Completed
Push — master ( 598bbe...becff8 )
by Mathieu
01:45 queued 12s
created

ContainerAwareTransChoice::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 ContainerAwareTransChoice extends BasePHPVisitor implements NodeVisitor
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26 2
    public function beforeTraverse(array $nodes): ?Node
27
    {
28 2
        return null;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function enterNode(Node $node): ?Node
35
    {
36 2
        if (!$node instanceof Node\Expr\MethodCall) {
37 2
            return null;
38
        }
39
40 2
        if (!\is_string($node->name) && !$node->name instanceof Node\Identifier) {
41 1
            return null;
42
        }
43 2
        $name = (string) $node->name;
44
45
        //If $this->get('translator')->transChoice('foobar')
46 2
        if ('transChoice' === $name) {
47 2
            $label = $this->getStringArgument($node, 0);
48 2
            if (null === $label) {
49 2
                return null;
50
            }
51 2
            $domain = $this->getStringArgument($node, 3);
52
53 2
            $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);
54
        }
55
56 2
        return null;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function leaveNode(Node $node): ?Node
63
    {
64 2
        return null;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function afterTraverse(array $nodes): ?Node
71
    {
72 2
        return null;
73
    }
74
}
75