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

FlashMessage   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 2
dl 0
loc 42
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeTraverse() 0 3 1
A leaveNode() 0 3 1
A afterTraverse() 0 3 1
C enterNode() 0 27 12
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 FlashMessage extends BasePHPVisitor implements NodeVisitor
22
{
23 2
    public function beforeTraverse(array $nodes)
24
    {
25 2
    }
26
27 2
    public function enterNode(Node $node)
28
    {
29 2
        if (!$node instanceof Node\Expr\MethodCall) {
30 2
            return;
31
        }
32
33 2
        if (!is_string($node->name) && !$node->name instanceof Node\Identifier) {
34 1
            return;
35
        }
36
37 2
        $name = (string) $node->name;
38 2
        $caller = $node->var;
39
        // $caller might be "Node\Expr\New_"
40 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...
41
42
        /*
43
         * Make sure the caller is from a variable named "this" or a function called "getFlashbag"
44
         */
45
        //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...
46 2
        if (('addFlash' === $name && 'this' === $callerName && $caller instanceof Node\Expr\Variable) ||
47 2
            ('add' === $name && 'getFlashBag' === $callerName && $caller instanceof Node\Expr\MethodCall)
48
        ) {
49 2
            if (null !== $label = $this->getStringArgument($node, 1)) {
50 2
                $this->addLocation($label, $node->getAttribute('startLine'), $node);
51
            }
52
        }
53 2
    }
54
55 2
    public function leaveNode(Node $node)
56
    {
57 2
    }
58
59 2
    public function afterTraverse(array $nodes)
60
    {
61 2
    }
62
}
63