Completed
Push — master ( 44b412...e96d03 )
by Andrey
02:04
created

ResolverItemProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setResolved() 0 4 1
A isResolved() 0 3 1
A tryResolve() 0 6 2
A getResolved() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Borodulin\Container\Autowire;
6
7
use Borodulin\Container\ContainerException;
8
9
class ResolverItemProvider
10
{
11
    /**
12
     * @var array
13
     */
14
    private $resolvedItems = [];
15
    /**
16
     * @var array
17
     */
18
    private $resolvingItems = [];
19
20 10
    public function isResolved(string $id): bool
21
    {
22 10
        return isset($this->resolvedItems[$id]);
23
    }
24
25 1
    public function getResolved($id): object
26
    {
27 1
        return $this->resolvedItems[$id];
28
    }
29
30 5
    public function setResolved(string $id, object $object): void
31
    {
32 5
        $this->resolvedItems[$id] = $object;
33 5
        unset($this->resolvingItems[$id]);
34 5
    }
35
36
    /**
37
     * @throws ContainerException
38
     */
39 10
    public function tryResolve(string $id): void
40
    {
41 10
        if (isset($this->resolvingItems[$id])) {
42 1
            throw new ContainerException("$id has circular reference dependency.");
43
        }
44 10
        $this->resolvingItems[$id] = true;
45 10
    }
46
}
47