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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 43
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 19 3
A inject() 0 14 2
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