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.

NamedMethodStrategy::inject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 2
rs 10
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
};
10
use Innmind\Immutable\Str;
11
12
/**
13
 * Looks for a method named exactly like the property
14
 *
15
 * Example:
16
 * <code>
17
 * private $foo;
18
 *
19
 * public function foo($foo);
20
 * </code>
21
 */
22
final class NamedMethodStrategy implements InjectionStrategy
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 9
    public function supports(object $object, string $property, $value): bool
28
    {
29 9
        $refl = new \ReflectionObject($object);
30
31 9
        $property = Str::of($property)
32 9
            ->camelize()
33 9
            ->toString();
34
35 9
        if (!$refl->hasMethod($property)) {
36 5
            return false;
37
        }
38
39 7
        $property = $refl->getMethod($property);
40
41 7
        if (!$property->isPublic()) {
42 1
            return false;
43
        }
44
45 7
        return $property->getNumberOfParameters() > 0;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 5
    public function inject(object $object, string $property, $value): object
52
    {
53 5
        if (!$this->supports($object, $property, $value)) {
54 1
            throw new LogicException;
55
        }
56
57 4
        $property = Str::of($property)
58 4
            ->camelize()
59 4
            ->toString();
60
61 4
        /** @psalm-suppress MixedMethodCall */
62
        $object->$property($value);
63 4
64
        return $object;
65
    }
66
}
67