Completed
Push — master ( ca9312...bb4483 )
by Дмитрий
12:32
created

NestedTernary::pass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 2
nop 2
dl 0
loc 14
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;
8
use PHPSA\Context;
9
10
class NestedTernary implements Pass\AnalyzerPassInterface
11
{
12
    use DefaultMetadataPassTrait;
13
14
    const DESCRIPTION = 'Discourages the use of nested ternaries.';
15
16
    /**
17
     * @param Expr\Ternary $expr
18
     * @param Context $context
19
     * @return bool
20
     */
21
    public function pass(Expr\Ternary $expr, Context $context)
22
    {
23
        if ($expr->if instanceof Expr\Ternary || $expr->else instanceof Expr\Ternary) {
24
            $context->notice(
25
                'nested_ternary',
26
                'Nested ternaries are confusing you should use if instead.',
27
                $expr
28
            );
29
30
            return true;
31
        }
32
33
        return false;
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getRegister()
40
    {
41
        return [
42
            Expr\Ternary::class,
43
        ];
44
    }
45
}
46