NotFluidSetter::getMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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\ClassMethod;
8
9
class NotFluidSetter extends Defect
10
{
11
    private
12
        $objectType;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $objectType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
        
14
    public function __construct(ObjectType $objectType, ClassMethod $node)
15
    {
16
        parent::__construct($node);
17
18
        $this->objectType = $objectType;        
19
    }    
20
    
21
    public function getMessage()
22
    {
23
        return sprintf(
24
            'Method <type>%s</type>::<id>%s</id>() does not follow fluid interface',
25
            $this->objectType->fullname,
26
            $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...
27
        );
28
    }
29
}
30