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.

SetterStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A supports() 0 13 2
A inject() 0 15 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
final class SetterStrategy implements InjectionStrategy
13
{
14
    private Str $setter;
15
16 6
    public function __construct()
17
    {
18 6
        $this->setter = Str::of('set%s');
19 6
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 9
    public function supports(object $object, string $property, $value): bool
25
    {
26 9
        $refl = new \ReflectionObject($object);
27 9
        $setter = $this
28 9
            ->setter
29
            ->sprintf(Str::of($property)->camelize()->ucfirst()->toString())
30
            ->toString();
31 9
32 7
        if (!$refl->hasMethod($setter)) {
33
            return false;
34
        }
35 5
36
        return $refl->getMethod($setter)->isPublic();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41 5
     */
42
    public function inject(object $object, string $property, $value): object
43 5
    {
44 1
        if (!$this->supports($object, $property, $value)) {
45
            throw new LogicException;
46
        }
47 4
48 4
        $setter = $this
49
            ->setter
50 4
            ->sprintf(Str::of($property)->camelize()->ucfirst()->toString())
51
            ->toString();
52 4
53
        /** @psalm-suppress MixedMethodCall */
54
        $object->$setter($value);
55
56
        return $object;
57
    }
58
}
59