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 ( 32827b...8dd213 )
by Baptiste
02:19
created

DefaultExtractionStrategies   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 46 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%
Metric Value
wmc 6
lcom 1
cbo 8
dl 23
loc 50
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 17 2
B get() 23 23 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
final class DefaultExtractionStrategies implements ExtractionStrategies
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 IsserStrategy,
31 5
                    new HasserStrategy,
32 5
                    new ReflectionStrategy,
33
                ]
34
            );
35
        }
36
37 1
        return $this->strategies;
38
    }
39
40 3 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...
41
    {
42 3
        $strategy = $this->getCachedStrategy(get_class($object), $key);
43 3
        if (null !== $strategy) {
44 1
            return $strategy;
45
        }
46
47 3
        foreach ($this->all() as $strategy) {
48 3
            if ($strategy->supports($object, $key)) {
49
50 2
                $this->setCachedStrategy(get_class($object), $key, $strategy);
51
52 3
                return $strategy;
53
            }
54
        }
55
56 1
        throw new LogicException(
57
            sprintf(
58 1
                'Property "%s" cannot be extracted',
59
                $key
60
            )
61
        );
62
    }
63
64
}
65