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

FlashMessage::enterNode()   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 25
Code Lines 11

Duplication

Lines 3
Ratio 12 %

Code Coverage

Tests 15
CRAP Score 11.0295

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 3
loc 25
ccs 15
cts 16
cp 0.9375
rs 5.2653
cc 11
eloc 11
nc 8
nop 1
crap 11.0295

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\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