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

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 2
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 3
rs 9.9332
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection\ExtractionStrategy;
5
6
use Innmind\Reflection\{
7
    ExtractionStrategy,
8
    Exception\LogicException,
9
};
10
use Innmind\Immutable\Str;
11
12
final class NamedMethodStrategy implements ExtractionStrategy
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 6
    public function supports(object $object, string $property): bool
18
    {
19 6
        $refl = new \ReflectionObject($object);
20
21 6
        $property = Str::of($property)
22 6
            ->camelize()
23 6
            ->toString();
24
25 6
        if (!$refl->hasMethod($property)) {
26 4
            return false;
27
        }
28
29 4
        $property = $refl->getMethod($property);
30
31 4
        if (!$property->isPublic()) {
32 1
            return false;
33
        }
34
35 4
        return $property->getNumberOfRequiredParameters() === 0;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 4
    public function extract(object $object, string $property)
42
    {
43 4
        if (!$this->supports($object, $property)) {
44 1
            throw new LogicException;
45
        }
46
47 3
        $property = Str::of($property)
48 3
            ->camelize()
49 3
            ->toString();
50
51 3
        /** @psalm-suppress MixedMethodCall */
52
        return $object->$property();
53
    }
54
}
55