1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Ray\Di\MultiBinding; |
6
|
|
|
|
7
|
|
|
use ArrayAccess; |
8
|
|
|
use Countable; |
9
|
|
|
use Generator; |
10
|
|
|
use Iterator; |
11
|
|
|
use IteratorAggregate; |
12
|
|
|
use LogicException; |
13
|
|
|
use Ray\Di\InjectorInterface; |
14
|
|
|
use ReturnTypeWillChange; |
|
|
|
|
15
|
|
|
|
16
|
|
|
use function array_key_exists; |
17
|
|
|
use function count; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @template T |
21
|
|
|
* @implements ArrayAccess<array-key, T> |
22
|
|
|
*/ |
23
|
|
|
final class Map implements IteratorAggregate, ArrayAccess, Countable |
24
|
|
|
{ |
25
|
|
|
/** @var array<array-key, Lazy> $lazies */ |
|
|
|
|
26
|
|
|
private $lazies; |
27
|
|
|
|
28
|
|
|
/** @var InjectorInterface */ |
29
|
|
|
private $injector; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param array<array-key, Lazy> $lazies |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
public function __construct(array $lazies, InjectorInterface $injector) |
35
|
|
|
{ |
36
|
|
|
$this->lazies = $lazies; |
37
|
|
|
$this->injector = $injector; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param array-key $offset |
|
|
|
|
42
|
|
|
* |
43
|
|
|
* @codeCoverageIgnore |
44
|
|
|
*/ |
45
|
|
|
#[ReturnTypeWillChange] |
46
|
|
|
public function offsetExists($offset): bool |
47
|
|
|
{ |
48
|
|
|
return array_key_exists($offset, $this->lazies); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param array-key $offset |
|
|
|
|
53
|
|
|
* |
54
|
|
|
* @return T |
55
|
|
|
* |
56
|
|
|
* @codeCoverageIgnore |
57
|
|
|
*/ |
58
|
|
|
#[ReturnTypeWillChange] |
59
|
|
|
public function offsetGet($offset) |
60
|
|
|
{ |
61
|
|
|
/** @var T $instance */ |
62
|
|
|
$instance = ($this->lazies[$offset])($this->injector); |
63
|
|
|
|
64
|
|
|
return $instance; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array-key $offset |
|
|
|
|
69
|
|
|
* @param mixed $value |
70
|
|
|
* |
71
|
|
|
* @return never |
72
|
|
|
* |
73
|
|
|
* @codeCoverageIgnore |
74
|
|
|
*/ |
75
|
|
|
#[ReturnTypeWillChange] |
76
|
|
|
public function offsetSet($offset, $value) |
77
|
|
|
{ |
78
|
|
|
unset($offset, $value); |
79
|
|
|
|
80
|
|
|
throw new LogicException(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array-key $offset |
|
|
|
|
85
|
|
|
* |
86
|
|
|
* @return never |
87
|
|
|
* |
88
|
|
|
* @codeCoverageIgnore |
89
|
|
|
*/ |
90
|
|
|
#[ReturnTypeWillChange] |
91
|
|
|
public function offsetUnset($offset) |
92
|
|
|
{ |
93
|
|
|
unset($offset); |
94
|
|
|
|
95
|
|
|
throw new LogicException(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** @return Generator<array-key, T, mixed, void> */ |
99
|
|
|
public function getIterator(): Iterator |
100
|
|
|
{ |
101
|
|
|
foreach ($this->lazies as $key => $lazy) { |
102
|
|
|
/** @var T $object */ |
103
|
|
|
$object = ($lazy)($this->injector); |
104
|
|
|
|
105
|
|
|
yield $key => $object; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function count(): int |
110
|
|
|
{ |
111
|
|
|
return count($this->lazies); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths