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

InjectionStrategies   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 56.36 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 8
dl 31
loc 55
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A all() 0 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\Reflection\{
6
    Cache\StrategyCachingCapabilities,
7
    Exception\LogicException,
8
    Exception\InvalidArgumentException
9
};
10
use Innmind\Immutable\{
11
    TypedCollection,
12
    TypedCollectionInterface
13
};
14
15
/**
16
 * DefaultInjectionStrategies
17
 *
18
 * @author Hugues Maignol <[email protected]>
19
 */
20
final class InjectionStrategies implements InjectionStrategiesInterface
21
{
22
    use StrategyCachingCapabilities;
23
24
    private $strategies;
25
26 38 View Code Duplication
    public function __construct(TypedCollectionInterface $strategies = null)
27
    {
28 38
        $this->strategies = $strategies ?? $this->all();
29
30 38
        if ($this->strategies->getType() !== InjectionStrategyInterface::class) {
31 2
            throw new InvalidArgumentException;
32
        }
33 36
    }
34
35 36
    public function all(): TypedCollectionInterface
36
    {
37 36
        if ($this->strategies === null) {
38 34
            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 34
                InjectionStrategyInterface::class,
40
                [
41 34
                    new SetterStrategy,
42 34
                    new NamedMethodStrategy,
43 34
                    new ReflectionStrategy,
44
                ]
45
            );
46
        }
47
48 18
        return $this->strategies;
49
    }
50
51 10 View Code Duplication
    public function get($object, string $key, $value): InjectionStrategyInterface
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...
52
    {
53 10
        $strategy = $this->getCachedStrategy(get_class($object), $key);
54 10
        if (null !== $strategy) {
55
            return $strategy;
56
        }
57
58 10
        foreach ($this->all() as $strategy) {
59 10
            if ($strategy->supports($object, $key, $value)) {
60
61 6
                $this->setCachedStrategy(get_class($object), $key, $strategy);
62
63 10
                return $strategy;
64
            }
65
        }
66
67 4
        throw new LogicException(
68
            sprintf(
69 4
                'Property "%s" cannot be injected',
70
                $key
71
            )
72
        );
73
    }
74
}
75