Completed
Push — master ( 3c2b8e...8f2461 )
by Дмитрий
07:09
created

StupidUnaryOperators::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 9.8333
c 0
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
    const DESCRIPTION = 'Checks for use of UnaryPlus `+$a` and suggests to use an int or float cast instead.';
15
16
    /**
17
     * @param Expr\UnaryPlus $expr
18
     * @param Context $context
19
     * @return bool
20
     */
21 11
    public function pass(Expr\UnaryPlus $expr, Context $context)
22
    {
23 11
        if (get_class($expr->expr) != get_class($expr)) {
24 11
            $context->notice(
25 11
                'stupid_unary_operators',
26 11
                'Better to use type casting then unary plus.',
27 11
                $expr
28
            );
29 11
            return true;
30
        }
31
32 1
        return false;
33
    }
34
35
    /**
36
     * @return array
37
     */
38 2
    public function getRegister()
39
    {
40
        return [
41 2
            Expr\UnaryPlus::class,
42
        ];
43
    }
44
}
45