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

PropertyDefinitionDefaultValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 15 3
A getRegister() 0 6 1
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