Completed
Pull Request — master (#134)
by Enrico
03:42
created

PropertyWithVar::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt\Property;
6
use PhpParser\Node\Stmt\Class_;
7
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
8
use PHPSA\Analyzer\Pass\ConfigurablePassInterface;
9
use PHPSA\Context;
10
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
11
12
class PropertyWithVar implements ConfigurablePassInterface, AnalyzerPassInterface
13
{
14
    /**
15
     * @param Property $stmt
16
     * @param Context $context
17
     * @return bool
18
     */
19 2
    public function pass(Property $stmt, Context $context)
20
    {
21 2
        if (!$stmt->isPrivate() && !$stmt->isProtected() && ($stmt->type & Class_::MODIFIER_PUBLIC) === 0) {
22 1
            $context->notice(
23 1
                'property.var',
24 1
                'Class property was defined with the deprecated var keyword. Use a visibility modifier instead',
25
                $stmt
26 1
            );
27 1
            return true;
28
        }
29 2
        return false;
30
    }
31
32
    /**
33
     * @return TreeBuilder
34
     */
35
    public function getConfiguration()
36
    {
37
        $treeBuilder = new TreeBuilder();
38
        $treeBuilder->root('property_with_var')
39
            ->canBeDisabled()
40
        ;
41
42
        return $treeBuilder;
43
    }
44
45
    /**
46
     * @return array
47
     */
48 1
    public function getRegister()
49
    {
50
        return [
51
            Property::class
52 1
        ];
53
    }
54
}
55