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

NestedTernary   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 14 3
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;
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