Completed
Push — 2.x ( ae2cb5...acdcc2 )
by Akihito
18s queued 13s
created

LazyProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\MultiBinding;
6
7
use Ray\Di\InjectorInterface;
8
use Ray\Di\ProviderInterface;
9
10
use function assert;
11
12
/**
13
 * @template T of ProviderInterface
14
 */
15
final class LazyProvider implements LazyInteterface
16
{
17
    /** @var class-string<T> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
18
    private $class;
19
20
    /**
21
     * @param class-string<T> $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
22
     */
23
    public function __construct(string $class)
24
    {
25
        $this->class = $class;
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31
    public function __invoke(InjectorInterface $injector)
32
    {
33
        $provider = $injector->getInstance($this->class);
34
        assert($provider instanceof ProviderInterface);
35
36
        return $provider->get();
37
    }
38
}
39