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 — develop ( 5e8f41...c39771 )
by Baptiste
06:33
created

DefaultExtractionStrategies::get()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 4
Metric Value
dl 23
loc 23
ccs 10
cts 10
cp 1
rs 8.7972
cc 4
eloc 12
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Innmind\Reflection\ExtractionStrategy;
4
5
use Innmind\Immutable\TypedCollection;
6
use Innmind\Immutable\TypedCollectionInterface;
7
use Innmind\Reflection\Cache\StrategyCachingCapabilities;
8
use Innmind\Reflection\Exception\LogicException;
9
10
/**
11
 * DefaultExtractionStrategies
12
 *
13
 * @author Hugues Maignol <[email protected]>
14
 */
15 View Code Duplication
final class DefaultExtractionStrategies implements ExtractionStrategies
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
18
    use StrategyCachingCapabilities;
19
20
    private $strategies;
21
22 5
    public function all(): TypedCollectionInterface
23
    {
24 5
        if ($this->strategies == null) {
25 5
            return $this->strategies = new TypedCollection(
26 5
                ExtractionStrategyInterface::class,
27
                [
28 5
                    new GetterStrategy,
29 5
                    new NamedMethodStrategy,
30 5
                    new ReflectionStrategy,
31
                ]
32
            );
33
        }
34
35 1
        return $this->strategies;
36
    }
37
38 3
    public function get($object, string $key): ExtractionStrategyInterface
39
    {
40 3
        $strategy = $this->getCachedStrategy(get_class($object), $key);
41 3
        if (null !== $strategy) {
42 1
            return $strategy;
43
        }
44
45 3
        foreach ($this->all() as $strategy) {
46 3
            if ($strategy->supports($object, $key)) {
47
48 2
                $this->setCachedStrategy(get_class($object), $key, $strategy);
49
50 3
                return $strategy;
51
            }
52
        }
53
54 1
        throw new LogicException(
55
            sprintf(
56 1
                'Property "%s" cannot be extracted',
57
                $key
58
            )
59
        );
60
    }
61
62
}
63