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

MapProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 12 1
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