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

FlashMessage::enterNode()   C

Complexity

Conditions 12
Paths 8

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 5.1612
c 0
b 0
f 0
cc 12
eloc 12
nc 8
nop 1
crap 12

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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