1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Ray\Di\MultiBinding; |
||
6 | |||
7 | use Koriym\ParamReader\ParamReaderInterface; |
||
8 | use Ray\Di\Di\Set; |
||
9 | use Ray\Di\Exception\SetNotFound; |
||
10 | use Ray\Di\InjectionPointInterface; |
||
11 | use Ray\Di\InjectorInterface; |
||
12 | use Ray\Di\ProviderInterface; |
||
13 | |||
14 | /** |
||
15 | * @implements ProviderInterface<Map> |
||
16 | */ |
||
17 | final class MapProvider implements ProviderInterface |
||
18 | { |
||
19 | /** @var MultiBindings */ |
||
20 | private $multiBindings; |
||
21 | |||
22 | /** @var InjectionPointInterface */ |
||
23 | private $ip; |
||
24 | |||
25 | /** @var InjectorInterface */ |
||
26 | private $injector; |
||
27 | |||
28 | /** @var ParamReaderInterface<object> */ |
||
29 | private $reader; |
||
30 | |||
31 | /** |
||
32 | * @param ParamReaderInterface<object> $reader |
||
33 | */ |
||
34 | public function __construct( |
||
35 | InjectionPointInterface $ip, |
||
36 | MultiBindings $multiBindings, |
||
37 | InjectorInterface $injector, |
||
38 | ParamReaderInterface $reader |
||
39 | ) { |
||
40 | $this->multiBindings = $multiBindings; |
||
41 | $this->ip = $ip; |
||
42 | $this->injector = $injector; |
||
43 | $this->reader = $reader; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return Map<mixed> |
||
48 | */ |
||
49 | public function get(): Map |
||
50 | { |
||
51 | /** @var ?Set<object> $set */ |
||
52 | $set = $this->reader->getParametrAnnotation($this->ip->getParameter(), Set::class); |
||
53 | if ($set === null) { |
||
54 | throw new SetNotFound((string) $this->ip->getParameter()); |
||
55 | } |
||
56 | |||
57 | /** @var array<string, LazyTo<object>> $lazies */ |
||
58 | $lazies = $this->multiBindings[$set->interface]; |
||
59 | |||
60 | return new Map($lazies, $this->injector); |
||
0 ignored issues
–
show
|
|||
61 | } |
||
62 | } |
||
63 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: