Completed
Pull Request — master (#14)
by Tobias
20:59 queued 19:01
created

FlashMessage::leaveNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
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\Model\SourceLocation;
17
use Translation\Extractor\Visitor\Php\BasePHPVisitor;
18
19
class FlashMessage extends BasePHPVisitor implements NodeVisitor
20
{
21 2
    public function beforeTraverse(array $nodes)
22
    {
23 2
    }
24
25 2
    public function enterNode(Node $node)
26
    {
27 2
        if ($node instanceof Node\Expr\MethodCall) {
28 2
            if (!is_string($node->name)) {
29
                return;
30
            }
31
32 2
            $name = $node->name;
33 2
            $caller = $node->var;
34
            // $caller might be "Node\Expr\New_"
35 2
            $callerName = isset($caller->name) ? $caller->name : '';
0 ignored issues
show
Bug introduced by
The property name does not seem to exist in PhpParser\Node\Expr.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
37
            /*
38
             * Make sure the caller is from a variable named "this" or a function called "getFlashbag"
39
             */
40
            //If $this->addFlash()  or xxx->getFlashbag()->add()
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
41 2
            if (('addFlash' === $name && $callerName === 'this' && $caller instanceof Node\Expr\Variable) ||
42 1
                ('add' === $name && $callerName === 'getFlashBag' && $caller instanceof Node\Expr\MethodCall)
43 2
            ) {
44 1 View Code Duplication
                if (null !== $label = $this->getStringArgument($node, 1)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
45 1
                    $this->collection->addLocation(new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine')));
46 1
                }
47 1
            }
48 2
        }
49 2
    }
50
51 2
    public function leaveNode(Node $node)
52
    {
53 2
    }
54
55 2
    public function afterTraverse(array $nodes)
56
    {
57 2
    }
58
}
59