These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | View Code Duplication | final class ContainerAwareTrans extends BasePHPVisitor implements NodeVisitor |
|
0 ignored issues
–
show
|
|||
22 | { |
||
23 | 4 | public function beforeTraverse(array $nodes) |
|
24 | { |
||
25 | 4 | } |
|
26 | |||
27 | 4 | public function enterNode(Node $node) |
|
28 | { |
||
29 | 4 | if (!$node instanceof Node\Expr\MethodCall) { |
|
30 | 4 | return; |
|
31 | } |
||
32 | |||
33 | 4 | if (!is_string($node->name) && !$node->name instanceof Node\Identifier) { |
|
34 | 1 | return; |
|
35 | } |
||
36 | 4 | $name = (string) $node->name; |
|
37 | |||
38 | //If $this->get('translator')->trans('foobar') |
||
39 | 4 | if ('trans' === $name) { |
|
40 | 4 | $label = $this->getStringArgument($node, 0); |
|
41 | 4 | $domain = $this->getStringArgument($node, 2); |
|
42 | |||
43 | 4 | $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]); |
|
44 | } |
||
45 | 4 | } |
|
46 | |||
47 | 4 | public function leaveNode(Node $node) |
|
48 | { |
||
49 | 4 | } |
|
50 | |||
51 | 4 | public function afterTraverse(array $nodes) |
|
52 | { |
||
53 | 4 | } |
|
54 | } |
||
55 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.