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::inject()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 5
nop 3
dl 0
loc 19
ccs 10
cts 10
cp 1
crap 4
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection\InjectionStrategy;
5
6
use Innmind\Reflection\{
7
    InjectionStrategy,
8
    Exception\LogicException,
9
    Visitor\AccessProperty,
10
};
11
12
final class ReflectionStrategy implements InjectionStrategy
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 9
    public function supports(object $object, string $property, $value): bool
18
    {
19
        try {
20 9
            (new AccessProperty)($object, $property);
21
22 6
            return true;
23 4
        } catch (\Exception $e) {
24 4
            return false;
25
        }
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 6
    public function inject(object $object, string $property, $value): object
32
    {
33 6
        if (!$this->supports($object, $property, $value)) {
34 1
            throw new LogicException;
35
        }
36
37 5
        $refl = (new AccessProperty)($object, $property);
38
39 5
        if (!$refl->isPublic()) {
40 5
            $refl->setAccessible(true);
41
        }
42
43 5
        $refl->setValue($object, $value);
44
45 5
        if (!$refl->isPublic()) {
46 5
            $refl->setAccessible(false);
47
        }
48
49 5
        return $object;
50
    }
51
}
52