Passed
Push — master ( ee03c1...dad2d2 )
by Alexander
02:31
created

DependencyResolver::invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
use Psr\Container\ContainerExceptionInterface;
8
use Psr\Container\ContainerInterface;
9
use Psr\Container\NotFoundExceptionInterface;
10
use Yiisoft\Factory\DependencyResolverInterface;
11
use Yiisoft\Injector\Injector;
12
13
/**
14
 * @internal
15
 */
16
final class DependencyResolver implements DependencyResolverInterface
17
{
18
    private ContainerInterface $container;
19
    private ?Injector $injector = null;
20
21 81
    public function __construct(ContainerInterface $container)
22
    {
23 81
        $this->container = $container;
24 81
    }
25
26
    /**
27
     * @param string $id
28
     *
29
     * @throws NotFoundExceptionInterface
30
     * @throws ContainerExceptionInterface
31
     *
32
     * @return mixed|object
33
     *
34
     * @psalm-suppress InvalidThrow
35
     */
36 55
    public function get($id)
37
    {
38 55
        return $this->container->get($id);
39
    }
40
41
    public function has($id): bool
42
    {
43
        return $this->container->has($id);
44
    }
45
46 44
    public function resolveReference(string $id)
47
    {
48 44
        return $this->get($id);
49
    }
50
51 17
    public function invoke(callable $callable)
52
    {
53 17
        return $this->getInjector()->invoke($callable);
54
    }
55
56 17
    private function getInjector(): Injector
57
    {
58 17
        return $this->injector ??= new Injector($this->container);
59
    }
60
}
61