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

DefaultInjectionStrategies   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 94.44%
Metric Value
wmc 6
lcom 1
cbo 6
dl 46
loc 46
ccs 17
cts 18
cp 0.9444
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 15 15 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\InjectionStrategy;
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
 * DefaultInjectionStrategies
12
 *
13
 * @author Hugues Maignol <[email protected]>
14
 */
15 View Code Duplication
final class DefaultInjectionStrategies implements InjectionStrategies
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
    use StrategyCachingCapabilities;
18
19
    private $strategies;
20
21 8
    public function all(): TypedCollectionInterface
22
    {
23 8
        if ($this->strategies == null) {
24 8
            return $this->strategies = new TypedCollection(
25 8
                InjectionStrategyInterface::class,
26
                [
27 8
                    new SetterStrategy,
28 8
                    new NamedMethodStrategy,
29 8
                    new ReflectionStrategy,
30
                ]
31
            );
32
        }
33
34 2
        return $this->strategies;
35
    }
36
37 5
    public function get($object, string $key, $value): InjectionStrategyInterface
38
    {
39 5
        $strategy = $this->getCachedStrategy(get_class($object), $key);
40 5
        if (null !== $strategy) {
41
            return $strategy;
42
        }
43
44 5
        foreach ($this->all() as $strategy) {
45 5
            if ($strategy->supports($object, $key, $value)) {
46
47 3
                $this->setCachedStrategy(get_class($object), $key, $strategy);
48
49 5
                return $strategy;
50
            }
51
        }
52
53 2
        throw new LogicException(
54
            sprintf(
55 2
                'Property "%s" cannot be injected',
56
                $key
57
            )
58
        );
59
    }
60
}
61