Passed
Pull Request — master (#105)
by Evgeniy
08:08 queued 04:03
created

Autowiring   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 6 2
A has() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Container;
6
7
use Cekta\DI\Container\Compiled\Factory;
8
use Cekta\DI\Exception\NotFound;
9
use Cekta\DI\Reflection;
10
use Psr\Container\ContainerInterface;
11
12
class Autowiring implements ContainerInterface
13
{
14
    /**
15
     * @var Reflection
16
     */
17
    private $reflection;
18
    /**
19
     * @var ContainerInterface
20
     */
21
    private $container;
22
23 15
    public function __construct(Reflection $reflection, ContainerInterface $container)
24
    {
25 15
        $this->reflection = $reflection;
26 15
        $this->container = $container;
27 15
    }
28
29 9
    public function get($id)
30
    {
31 9
        if (!$this->has($id)) {
32 3
            throw new NotFound($id);
33
        }
34 6
        return (new Factory($id, ...$this->reflection->getDependencies($id)))($this->container);
35
    }
36
37 12
    public function has($id): bool
38
    {
39 12
        return $this->reflection->isInstantiable($id);
40
    }
41
}
42