Test Failed
Push — move-injector ( c9b05e )
by Sergei
03:08
created

DependencyResolver   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 3 1
A getInjector() 0 6 2
A get() 0 3 1
A invoke() 0 3 1
A has() 0 3 1
A __construct() 0 3 1
A shouldCloneOnResolve() 0 3 1
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
    public function __construct(ContainerInterface $container)
22
    {
23
        $this->container = $container;
24
    }
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
    public function get($id)
37
    {
38
        return $this->container->get($id);
39
    }
40
41
    public function has($id): bool
42
    {
43
        return $this->container->has($id);
44
    }
45
46
    /**
47
     * @param string $id
48
     *
49
     * @throws NotFoundExceptionInterface
50
     * @throws ContainerExceptionInterface
51
     *
52
     * @return mixed|object
53
     *
54
     * @psalm-suppress InvalidThrow
55
     */
56
    public function resolve(string $id)
57
    {
58
        return $this->get($id);
59
    }
60
61
    public function invoke(callable $callable)
62
    {
63
        return $this->getInjector()->invoke($callable);
64
    }
65
66
    public function shouldCloneOnResolve(): bool
67
    {
68
        return false;
69
    }
70
71
    private function getInjector(): Injector
72
    {
73
        if ($this->injector === null) {
74
            $this->injector = new Injector($this->container);
75
        }
76
        return $this->injector;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->injector could return the type null which is incompatible with the type-hinted return Yiisoft\Injector\Injector. Consider adding an additional type-check to rule them out.
Loading history...
77
    }
78
}
79