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

ResolverItemProvider::getResolved()   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
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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