Completed
Push — master ( 565f24...90df96 )
by Tobias
03:38
created

ContainerAwareTrans   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 34
loc 34
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 3 3 1
A afterTraverse() 3 3 1
A beforeTraverse() 3 3 1
B enterNode() 19 19 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
22
{
23 3
    public function beforeTraverse(array $nodes)
24
    {
25 3
    }
26
27 3
    public function enterNode(Node $node)
28
    {
29 3
        if (!$node instanceof Node\Expr\MethodCall) {
30 3
            return;
31
        }
32
33 3
        if (!is_string($node->name) && !$node->name instanceof Node\Identifier) {
34 1
            return;
35
        }
36 3
        $name = (string) $node->name;
37
38
        //If $this->get('translator')->trans('foobar')
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39 3
        if ('trans' === $name) {
40 3
            $label = $this->getStringArgument($node, 0);
41 3
            $domain = $this->getStringArgument($node, 2);
42
43 3
            $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);
44
        }
45 3
    }
46
47 3
    public function leaveNode(Node $node)
48
    {
49 3
    }
50
51 3
    public function afterTraverse(array $nodes)
52
    {
53 3
    }
54
}
55