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 ( 4725ce...7d1107 )
by Baptiste
11s
created

ReflectionClass   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Test Coverage

Coverage 97.37%

Importance

Changes 0
Metric Value
dl 0
loc 122
ccs 37
cts 38
cp 0.9737
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A withProperty() 0 7 1
A properties() 0 3 1
A build() 0 18 1
A withProperties() 0 13 2
A instanciator() 0 3 1
A __construct() 0 19 3
A injectionStrategy() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Reflection;
5
6
use Innmind\Reflection\{
7
    InjectionStrategy\InjectionStrategies,
8
    Instanciator\ReflectionInstanciator,
9
    Exception\InvalidArgumentException
10
};
11
use Innmind\Immutable\{
12
    MapInterface,
13
    Map
14
};
15
16
class ReflectionClass
17
{
18
    private $class;
19
    private $properties;
20
    private $injectionStrategy;
21
    private $instanciator;
22
23 5
    public function __construct(
24
        string $class,
25
        MapInterface $properties = null,
26
        InjectionStrategyInterface $injectionStrategy = null,
27
        InstanciatorInterface $instanciator = null
28
    ) {
29 5
        $properties = $properties ?? new Map('string', 'mixed');
30
31
        if (
32 5
            (string) $properties->keyType() !== 'string' ||
33 5
            (string) $properties->valueType() !== 'mixed'
34
        ) {
35
            throw new InvalidArgumentException;
36
        }
37
38 5
        $this->class = $class;
39 5
        $this->properties = $properties;
40 5
        $this->injectionStrategy = $injectionStrategy ?? InjectionStrategies::default();
41 5
        $this->instanciator = $instanciator ?? new ReflectionInstanciator;
42 5
    }
43
44
    /**
45
     * Add a property to be injected in the new object
46
     *
47
     * @param string $property
48
     * @param mixed  $value
49
     *
50
     * @return self
51
     */
52 2
    public function withProperty(string $property, $value): self
53
    {
54 2
        return new self(
55 2
            $this->class,
56 2
            $this->properties->put($property, $value),
57 2
            $this->injectionStrategy,
58 2
            $this->instanciator
59
        );
60
    }
61
62
    /**
63
     * Add a set of properties that need to be injected
64
     *
65
     * @param array<string, mixed> $properties
66
     *
67
     * @return self
68
     */
69 1
    public function withProperties(array $properties): self
70
    {
71 1
        $map = $this->properties;
72
73 1
        foreach ($properties as $key => $value) {
74 1
            $map = $map->put($key, $value);
75
        }
76
77 1
        return new self(
78 1
            $this->class,
79 1
            $map,
80 1
            $this->injectionStrategy,
81 1
            $this->instanciator
82
        );
83
    }
84
85
    /**
86
     * Return the collection of properties that will be injected in the object
87
     *
88
     * @return MapInterface<string, mixed>
89
     */
90 1
    public function properties(): MapInterface
91
    {
92 1
        return $this->properties;
93
    }
94
95
    /**
96
     * Return the list of injection strategies used
97
     *
98
     * @return InjectionStrategiesInterface
0 ignored issues
show
Bug introduced by
The type Innmind\Reflection\InjectionStrategiesInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
99
     */
100 1
    public function injectionStrategy(): InjectionStrategyInterface
101
    {
102 1
        return $this->injectionStrategy;
103
    }
104
105
    /**
106
     * Return the object instanciator
107
     *
108
     * @return InstanciatorInterface
109
     */
110 1
    public function instanciator(): InstanciatorInterface
111
    {
112 1
        return $this->instanciator;
113
    }
114
115
    /**
116
     * Return a new instance of the class
117
     *
118
     * @return object
119
     */
120 2
    public function build()
121
    {
122 2
        $object = $this->instanciator->build($this->class, $this->properties);
123 2
        $parameters = $this->instanciator->parameters($this->class);
124
125
        //avoid injecting the properties already used in the constructor
126
        $properties = $this
127 2
            ->properties
128 2
            ->filter(function(string $property) use ($parameters) {
129 1
                return !$parameters->contains($property);
130 2
            });
131
        $refl = new ReflectionObject(
132
            $object,
133
            $properties,
134
            $this->injectionStrategy
135
        );
136
137
        return $refl->build();
138
    }
139
}
140