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.
Completed
Push — master ( de8df8...cc25ac )
by Baptiste
03:22
created

DelegationStrategy::generateKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\InvalidArgumentException,
9
    Exception\PropertyCannotBeExtracted,
10
};
11
use Innmind\Immutable\{
12
    Stream,
13
    Map,
14
};
15
16
final class DelegationStrategy implements ExtractionStrategy
17
{
18
    private $strategies;
19
    private $cache;
20
21 7
    public function __construct(ExtractionStrategy ...$strategies)
22
    {
23 7
        $this->strategies = Stream::of(ExtractionStrategy::class, ...$strategies);
24 7
        $this->cache = new Map('string', ExtractionStrategy::class);
25 7
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function supports(object $object, string $property): bool
31
    {
32
        return $this
33 1
            ->strategies
34 1
            ->reduce(
35 1
                false,
36
                function(bool $supports, ExtractionStrategy $strategy) use ($object, $property): bool {
37 1
                    return $supports || $strategy->supports($object, $property);
38 1
                }
39
            );
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 6
    public function extract(object $object, string $property)
46
    {
47 6
        $key = $this->generateKey($object, $property);
48
49 6
        if ($this->cache->contains($key)) {
50
            return $this
51 1
                ->cache
52 1
                ->get($key)
53 1
                ->extract($object, $property);
54
        }
55
56 6
        $strategy = $this->strategies->reduce(
57 6
            null,
58
            function(?ExtractionStrategy $target, ExtractionStrategy $strategy) use ($object, $property): ?ExtractionStrategy {
59 6
                return $target ?? ($strategy->supports($object, $property) ? $strategy : null);
60 6
            }
61
        );
62
63 6
        if (!$strategy instanceof ExtractionStrategy) {
64 2
            throw new PropertyCannotBeExtracted($property);
65
        }
66
67 4
        $this->cache = $this->cache->put($key, $strategy);
68
69 4
        return $strategy->extract($object, $property);
70
    }
71
72 6
    private function generateKey(object $object, string $property): string
73
    {
74 6
        return get_class($object).'::'.$property;
75
    }
76
}
77