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

StupidUnaryOperators   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 13 2
A getRegister() 0 6 1
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