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 ( 993dc1...11510d )
by Baptiste
02:04
created

ReflectionStrategy::property()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
crap 3.0261
1
<?php
2
declare(strict_types = 1);
3
namespace Innmind\Reflection\ExtractionStrategy;
4
use Innmind\Reflection\Exception\LogicException;
5
class ReflectionStrategy implements ExtractionStrategyInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10 16
    public function supports($object, string $property): bool
11
    {
12
        try {
13 16
            $this->property(get_class($object), $property);
14
15 12
            return true;
16 6
        } catch (\Exception $e) {
17 6
            return false;
18
        }
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 10 View Code Duplication
    public function extract($object, string $property)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26 10
        if (!$this->supports($object, $property)) {
27 2
            throw new LogicException;
28
        }
29
30 8
        $refl = $this->property(get_class($object), $property);
31
32 8
        if (!$refl->isPublic()) {
33 6
            $refl->setAccessible(true);
34
        }
35
36 8
        $value = $refl->getValue($object);
37
38 8
        if (!$refl->isPublic()) {
39 6
            $refl->setAccessible(false);
40
        }
41
42 8
        return $value;
43
    }
44
45 16
    private function property(string $class, string $property): \ReflectionProperty
46
    {
47 16
        $refl = new \ReflectionClass($class);
48
49 16
        if ($refl->hasProperty($property)) {
50 12
            return $refl->getProperty($property);
51
        }
52
53 6
        if ($refl->getParentClass()) {
54
            return $this->property($refl->getParentClass()->getName(), $property);
55
        }
56
57 6
        throw new \Exception;
58
    }
59
}
60