PublicClass::getMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Solidifier\Defects;
4
5
use Solidifier\Defect;
6
use Solidifier\Visitors\ObjectType;
7
use PhpParser\Node\Stmt\Property;
8
use PhpParser\Node\Stmt\Class_;
9
10
class PublicClass extends Defect
11
{
12
    public function getMessage()
13
    {
14
        return sprintf(
15
            'Class <id>%s</id> is mainly public : maybe it is over responsible',
16
            $this->node->name
0 ignored issues
show
Bug introduced by
Accessing name on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
17
        );
18
    }
19
}
20