Completed
Pull Request — master (#231)
by
unknown
04:17
created

StupidUnaryOperators   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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\Pass\AnalyzerPassInterface;
7
use PHPSA\Context;
8
9
class StupidUnaryOperators implements AnalyzerPassInterface
10
{
11
    /**
12
     * @param Expr $expr
13
     * @param Context $context
14
     * @return bool
15
     */
16 11
    public function pass(Expr $expr, Context $context)
17
    {
18 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...
19 11
            $context->notice(
20 11
                'stupid_unary_operators',
21 11
                'You are using single plus unary operator. This has no effect',
22
                $expr
23 11
            );
24 11
            return true;
25
        }
26
27 1
        return false;
28
    }
29
30
    /**
31
     * @return array
32
     */
33 1
    public function getRegister()
34
    {
35
        return [
36 1
            Expr\UnaryPlus::class,
37 1
        ];
38
    }
39
}
40