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.
Completed
Push — master ( f00018...f19ece )
by Baptiste
02:02
created

AccessProperty::byClass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 2
crap 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection\Visitor;
5
6
use Innmind\Reflection\Exception\{
7
    PropertyNotFoundException,
8
    InvalidArgumentException
9
};
10
11
final class AccessProperty
12
{
13
    /**
14
     * @throws PropertyNotFoundException
15
     */
16 50
    public function __invoke($object, string $property): \ReflectionProperty
17
    {
18 50
        if (!is_object($object)) {
19 2
            throw new InvalidArgumentException;
20
        }
21
22
        try {
23 48
            return $this->byObject($object, $property);
24 24
        } catch (PropertyNotFoundException $e) {
25 24
            return $this->byClass(get_class($object), $property);
26
        }
27
    }
28
29 48
    private function byObject($object, string $property): \ReflectionProperty
30
    {
31 48
        $refl = new \ReflectionObject($object);
32
33 48
        if ($refl->hasProperty($property)) {
34 28
            return $refl->getProperty($property);
35
        }
36
37 24
        throw new PropertyNotFoundException;
38
    }
39
40 24
    private function byClass(string $class, string $property): \ReflectionProperty
41
    {
42 24
        $refl = new \ReflectionClass($class);
43
44 24
        if ($refl->hasProperty($property)) {
45 8
            return $refl->getProperty($property);
46
        }
47
48 24
        if ($refl->getParentClass()) {
49 8
            return $this->byClass(
50 8
                $refl->getParentClass()->getName(),
51
                $property
52
            );
53
        }
54
55 16
        throw new PropertyNotFoundException;
56
    }
57
}
58