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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 47
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 3
A byObject() 0 10 2
A byClass() 0 17 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