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.

ReflectionStrategy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 1
b 1
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 8 2
A extract() 0 20 4
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection\ExtractionStrategy;
5
6
use Innmind\Reflection\{
7
    ExtractionStrategy,
8
    Exception\LogicException,
9
    Visitor\AccessProperty,
10
};
11
12
final class ReflectionStrategy implements ExtractionStrategy
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 8
    public function supports(object $object, string $property): bool
18
    {
19
        try {
20 8
            (new AccessProperty)($object, $property);
21
22 6
            return true;
23 3
        } catch (\Exception $e) {
24 3
            return false;
25
        }
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 5
    public function extract(object $object, string $property)
32
    {
33 5
        if (!$this->supports($object, $property)) {
34 1
            throw new LogicException;
35
        }
36
37 4
        $refl = (new AccessProperty)($object, $property);
38
39 4
        if (!$refl->isPublic()) {
40 2
            $refl->setAccessible(true);
41
        }
42
43 4
        /** @var mixed $value */
44
        $value = $refl->getValue($object);
45 4
46 2
        if (!$refl->isPublic()) {
47
            $refl->setAccessible(false);
48
        }
49 4
50
        return $value;
51
    }
52
}
53