Completed
Push — 2.x ( 5c5bb8...ae2cb5 )
by Akihito
20s queued 13s
created

MapProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\MultiBinding;
6
7
use Ray\Di\Di\Set;
8
use Ray\Di\InjectionPointInterface;
9
use Ray\Di\InjectorInterface;
10
use Ray\Di\ProviderInterface;
11
use ReflectionAttribute;
12
13
final class MapProvider implements ProviderInterface
14
{
15
    /** @var LazyCollection */
16
    private $lazyCollection;
17
18
    /** @var InjectionPointInterface */
19
    private $ip;
20
21
    /** @var InjectorInterface */
22
    private $injector;
23
24
    public function __construct(InjectionPointInterface $ip, LazyCollection $lazyCollection, InjectorInterface $injector)
25
    {
26
        $this->lazyCollection = $lazyCollection;
27
        $this->ip = $ip;
28
        $this->injector = $injector;
29
    }
30
31
    public function get(): Map
32
    {
33
        /** @var array<ReflectionAttribute> $attributes */
34
        $attributes = $this->ip->getParameter()->getAttributes(Set::class);
35
        $set = $attributes[0];
36
        /** @var Set $instance */
37
        $instance = $set->newInstance();
38
39
        /** @var array<string, Lazy<object>> $keyBasedLazy */
40
        $keyBasedLazy = $this->lazyCollection[$instance->interface];
41
42
        return new Map($keyBasedLazy, $this->injector);
43
    }
44
}
45