PublicAttributes::enter()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 4
nop 1
1
<?php
2
3
namespace Solidifier\Visitors\Encapsulation;
4
5
use Solidifier\Parser\Visitors\ContextualVisitor;
6
use PhpParser\Node;
7
use PhpParser\Node\Stmt\Property;
8
9
class PublicAttributes extends ContextualVisitor
10
{
11
    protected function enter(Node $node)
12
    {
13
        if($node instanceof Property)
14
        {
15
            if($node->isPublic())
16
            {
17
                foreach($node->props as $property)
18
                {
19
                    $this->dispatch(
20
                        new \Solidifier\Defects\PublicAttribute($this->currentObjectType, $property->name, $node)
0 ignored issues
show
Bug introduced by
It seems like $this->currentObjectType can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
21
                    );
22
                }
23
            }   
24
        }
25
    }
26
}