LazyProvider::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 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