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

PropertyWithVar   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
ccs 10
cts 15
cp 0.6667
rs 10
wmc 6
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 12 4
A getConfiguration() 0 9 1
A getRegister() 0 6 1
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