Completed
Pull Request — master (#275)
by Enrico
10:31
created

NestedTernary::pass()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
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 3
    public function pass(Expr\Ternary $expr, Context $context)
22
    {
23 3
        if ($expr->if instanceof Expr\Ternary || $expr->else instanceof Expr\Ternary) {
24 1
            $context->notice(
25 1
                'nested_ternary',
26 1
                'Nested ternaries are confusing you should use if instead.',
27
                $expr
28 1
            );
29
30 1
            return true;
31
        }
32
33 3
        return false;
34
    }
35
36
    /**
37
     * @return array
38
     */
39 1
    public function getRegister()
40
    {
41
        return [
42 1
            Expr\Ternary::class,
43 1
        ];
44
    }
45
}
46