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
Branch master (993dc1)
by Baptiste
07:34 queued 03:48
created

ExtractionStrategies::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Innmind\Reflection\ExtractionStrategy;
4
5
use Innmind\Reflection\{
6
    Cache\StrategyCachingCapabilities,
7
    Exception\LogicException,
8
    Exception\InvalidArgumentException
9
};
10
use Innmind\Immutable\{
11
    TypedCollection,
12
    TypedCollectionInterface
13
};
14
15
/**
16
 * DefaultExtractionStrategies
17
 *
18
 * @author Hugues Maignol <[email protected]>
19
 */
20
final class ExtractionStrategies implements ExtractionStrategiesInterface
21
{
22
    use StrategyCachingCapabilities;
23
24
    private $strategies;
25
26 32 View Code Duplication
    public function __construct(TypedCollectionInterface $strategies = null)
27
    {
28 32
        $this->strategies = $strategies ?? $this->all();
29
30 32
        if ($this->strategies->getType() !== ExtractionStrategyInterface::class) {
31 2
            throw new InvalidArgumentException;
32
        }
33 30
    }
34
35 30
    public function all(): TypedCollectionInterface
36
    {
37 30
        if ($this->strategies === null) {
38 28
            return $this->strategies = new TypedCollection(
0 ignored issues
show
Deprecated Code introduced by
The class Innmind\Immutable\TypedCollection has been deprecated with message: To be removed in 2.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
39 28
                ExtractionStrategyInterface::class,
40
                [
41 28
                    new GetterStrategy,
42 28
                    new NamedMethodStrategy,
43 28
                    new IsserStrategy,
44 28
                    new HasserStrategy,
45 28
                    new ReflectionStrategy,
46
                ]
47
            );
48
        }
49
50 12
        return $this->strategies;
51
    }
52
53 6 View Code Duplication
    public function get($object, string $key): ExtractionStrategyInterface
0 ignored issues
show
Duplication introduced by
This method 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...
54
    {
55 6
        $strategy = $this->getCachedStrategy(get_class($object), $key);
56 6
        if (null !== $strategy) {
57 2
            return $strategy;
58
        }
59
60 6
        foreach ($this->all() as $strategy) {
61 6
            if ($strategy->supports($object, $key)) {
62
63 4
                $this->setCachedStrategy(get_class($object), $key, $strategy);
64
65 6
                return $strategy;
66
            }
67
        }
68
69 2
        throw new LogicException(
70
            sprintf(
71 2
                'Property "%s" cannot be extracted',
72
                $key
73
            )
74
        );
75
    }
76
77
}
78