Completed
Push — master ( 2e7974...c9bbf8 )
by Enrico
06:49 queued 02:32
created

StupidUnaryOperators::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Expression;
4
5
use PhpParser\Node\Expr;
6
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
7
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
8
use PHPSA\Context;
9
10
class StupidUnaryOperators implements AnalyzerPassInterface
11
{
12
    use DefaultMetadataPassTrait;
13
14
    /**
15
     * @param Expr $expr
16
     * @param Context $context
17
     * @return bool
18
     */
19 11
    public function pass(Expr $expr, Context $context)
20
    {
21 11
        if (get_class($expr->expr) != get_class($expr)) {
0 ignored issues
show
Bug introduced by
The property expr 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...
22 11
            $context->notice(
23 11
                'stupid_unary_operators',
24 11
                'Better to use type casting then unary plus.',
25
                $expr
26 11
            );
27 11
            return true;
28
        }
29
30 1
        return false;
31
    }
32
33
    /**
34
     * @return array
35
     */
36 1
    public function getRegister()
37
    {
38
        return [
39 1
            Expr\UnaryPlus::class,
40 1
        ];
41
    }
42
}
43