Passed
Push — phpdoc ( 24498c )
by Akihito
02:30
created

InjectingProviderProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ get() 0 3 1
A __construct() 0 4 1
A hp$0 ➔ __construct() 0 4 1
get() 0 23 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Di\Di\Set;
8
9
use function assert;
10
11
final class InjectingProviderProvider implements ProviderInterface
12
{
13
    private InjectionPointInterface $ip;
14
    private InjectorInterface $injector;
15
16
    public function __construct(InjectionPointInterface $ip, InjectorInterface $injector)
17
    {
18
        $this->ip = $ip;
19
        $this->injector = $injector;
20
    }
21
22
    /**
23
     * @return mixed
24
     */
25
    public function get()
26
    {
27
        $set = $this->ip->getParameter()->getAttributes(Set::class)[0];
28
        $instance = $set->newInstance();
29
        assert($instance instanceof Set);
30
31
        return new class ($this->injector, $instance) implements ProviderInterface
32
        {
33
            private InjectorInterface $injector;
34
            private Set $set;
35
36
            public function __construct(InjectorInterface $injector, Set $set)
37
            {
38
                $this->injector = $injector;
39
                $this->set = $set;
40
            }
41
42
            /**
43
             * @return mixed
44
             */
45
            public function get()
46
            {
47
                return $this->injector->getInstance($this->set->interface, $this->set->name);
48
            }
49
        };
50
    }
51
}
52