Passed
Push — master ( 1e65a5...6cebba )
by SignpostMarv
03:39
created

ClassReflectionExtension::hasProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
* Base daft objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject\DaftNestedObject\PHPStan;
10
11
use PHPStan\Broker\Broker;
12
use PHPStan\Reflection\BrokerAwareExtension;
13
use PHPStan\Reflection\ClassReflection;
14
use PHPStan\Reflection\PropertiesClassReflectionExtension;
15
use PHPStan\Reflection\PropertyReflection;
16
use SignpostMarv\DaftObject\DaftNestedObject;
17
use SignpostMarv\DaftObject\PHPStan\ClassReflectionExtension as Base;
18
19
class ClassReflectionExtension extends Base
20
{
21
    /**
22
    * @var Broker|null
23
    */
24
    private $broker;
25
26
    public function setBroker(Broker $broker) : void
27
    {
28
        $this->broker = $broker;
29
    }
30
31
    public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
32
    {
33
        $className = $classReflection->getName();
0 ignored issues
show
Unused Code introduced by
The assignment to $className is dead and can be removed.
Loading history...
34
35
        $property = ucfirst($propertyName);
36
37
        return
38
            parent::hasProperty($classReflection, $property) ||
39
            in_array($property, [
40
                'intNestedLeft',
41
                'intNestedRight',
42
                'intNestedLevel',
43
                'intNestedParentId'
44
            ]);
45
    }
46
47
    public function getProperty(ClassReflection $ref, string $propertyName) : PropertyReflection
48
    {
49
        return new PropertyReflectionExtension($ref, $this->broker, $propertyName);
0 ignored issues
show
Bug introduced by
It seems like $this->broker can also be of type null; however, parameter $broker of SignpostMarv\DaftObject\...xtension::__construct() does only seem to accept PHPStan\Broker\Broker, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        return new PropertyReflectionExtension($ref, /** @scrutinizer ignore-type */ $this->broker, $propertyName);
Loading history...
50
    }
51
}
52