Completed
Pull Request — master (#247)
by
unknown
12:18 queued 08:01
created

PropertyDefinitionDefaultValue::pass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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