Completed
Push — master ( c84f1e...3048e8 )
by Enrico
12:15
created

PropertyDefinitionDefaultValue::pass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 15
ccs 11
cts 11
cp 1
crap 3
rs 9.4285
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt;
6
use PhpParser\Node;
7
use PhpParser\Node\Expr;
8
use PhpParser\Node\Stmt\PropertyProperty;
9
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
10
use PHPSA\Analyzer\Pass;
11
use PHPSA\Context;
12
use PHPSA\CompiledExpression;
13
14
class PropertyDefinitionDefaultValue implements Pass\AnalyzerPassInterface
15
{
16
    use DefaultMetadataPassTrait;
17
18
    /**
19
     * @param $stmt
20
     * @param Context $context
21
     * @return bool
22
     */
23 2
    public function pass($stmt, Context $context)
24
    {
25 2
        if ($stmt->default instanceof Node\Expr) {
26 2
            $compiled = $context->getExpressionCompiler()->compile($stmt->default);
27 2
            if ($compiled->getType() == CompiledExpression::NULL) {
28 1
                $context->notice(
29 1
                    'property_definition_default_value',
30 1
                    'null is default and is not needed.',
31
                    $stmt
32 1
                );
33 1
                return true;
34
            }
35 1
        }
36 2
        return false;
37
    }
38
39
    /**
40
     * @return array
41
     */
42 1
    public function getRegister()
43
    {
44
        return [
45 1
            PropertyProperty::class,
46 1
        ];
47
    }
48
}
49