Completed
Push — master ( 2b19b6...bcf79f )
by Pádraic
02:36
created

IgnoreNamespaceScoperNodeVisitor::enterNode()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 10
nc 4
nop 1
dl 0
loc 17
ccs 0
cts 11
cp 0
crap 72
rs 7.7777
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper\NodeVisitor;
16
17
use PhpParser\Node;
18
use PhpParser\Node\Name\FullyQualified;
19
use PhpParser\Node\Stmt\UseUse;
20
use PhpParser\NodeVisitorAbstract;
21
22
final class IgnoreNamespaceScoperNodeVisitor extends NodeVisitorAbstract
23
{
24
    /**
25
     * @inheritdoc
26
     */
27
    public function enterNode(Node $node)
28
    {
29
        if ($node instanceof FullyQualified
30
            && $node->isFullyQualified()
31
            && 1 === count($node->getSubNodeNames())
32
        ) {
33
            $node->setAttribute('phpscoper_ignore', true);
34
        }
35
36
        if ($node instanceof UseUse
37
            && $node->hasAttribute('parent')
38
            && false === ($node->getAttribute('parent') instanceof GroupUse)
0 ignored issues
show
Bug introduced by
The class Humbug\PhpScoper\NodeVisitor\GroupUse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
39
            && 1 === count($node->name->parts)
1 ignored issue
show
Deprecated Code introduced by
The property PhpParser\Node\Name::$parts has been deprecated with message: Avoid directly accessing $parts, use methods instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
40
        ) {
41
            $node->setAttribute('phpscoper_ignore', true);
42
        }
43
    }
44
}
45