PublicAttributes   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A enter() 0 15 4
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
}