GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 2fb392...923b97 )
by SignpostMarv
04:18
created

ClassReflectionExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 6
1
<?php
2
/**
3
* Base daft objects.
4
*
5
* @author SignpostMarv
6
*/
7
declare(strict_types=1);
8
9
namespace SignpostMarv\DaftObject\PHPStan;
10
11
use BadMethodCallException;
12
use PHPStan\Broker\Broker;
13
use PHPStan\Reflection\BrokerAwareExtension;
14
use PHPStan\Reflection\ClassReflection;
15
use PHPStan\Reflection\PropertiesClassReflectionExtension;
16
use PHPStan\Reflection\PropertyReflection;
17
use SignpostMarv\DaftObject\DaftObject;
18
use SignpostMarv\DaftObject\TypeParanoia;
19
use SignpostMarv\DaftObject\TypeUtilities;
20
21
class ClassReflectionExtension implements BrokerAwareExtension, PropertiesClassReflectionExtension
22
{
23
    const BOOL_SETNOTGET_SETTER = true;
24
25
    const BOOL_SETNOTGET_GETTER = false;
26
27
    /**
28
    * @var Broker|null
29
    */
30
    private $broker;
31
32
    public function setBroker(Broker $broker) : void
33
    {
34
        $this->broker = $broker;
35
    }
36
37
    public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool
38
    {
39
        $className = $classReflection->getName();
40
41
        $property = ucfirst($propertyName);
42
        $getter = TypeUtilities::MethodNameFromProperty($property, self::BOOL_SETNOTGET_GETTER);
43
        $setter = TypeUtilities::MethodNameFromProperty($property, self::BOOL_SETNOTGET_SETTER);
44
45
        return
46
            TypeParanoia::IsThingStrings($className, DaftObject::class) &&
47
            (
48
                $classReflection->getNativeReflection()->hasMethod($getter) ||
49
                $classReflection->getNativeReflection()->hasMethod($setter)
50
            );
51
    }
52
53
    public function getProperty(ClassReflection $ref, string $propertyName) : PropertyReflection
54
    {
55
        if ( ! ($this->broker instanceof Broker)) {
56
            throw new BadMethodCallException(
57
                'Broker expected to be specified when calling ' .
58
                __METHOD__
59
            );
60
        }
61
62
        return new PropertyReflectionExtension($ref, $this->broker, $propertyName);
63
    }
64
}
65