Test Failed
Pull Request — master (#870)
by Aleksei
08:56
created

Binder::bindSingleton()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 2
nop 2
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core\Internal;
6
7
use Psr\Container\ContainerInterface;
8
use Spiral\Core\Internal\Common\DestructorTrait;
9
use Spiral\Core\Internal\Common\Registry;
10
use Spiral\Core\Internal\Config\StateBinder;
11
12
/**
13
 * @internal
14
 */
15
final class Binder extends StateBinder
16
{
17
    use DestructorTrait;
18
19
    private ContainerInterface $container;
20
21
    public function __construct(Registry $constructor)
22
    {
23
        $constructor->set('binder', $this);
24
25
        $this->container = $constructor->get('container', ContainerInterface::class);
26 1004
        parent::__construct($constructor->get('state', State::class));
27
    }
28 1004
29
    public function hasInstance(string $alias): bool
30 1004
    {
31 1004
        if (!$this->container->has($alias)) {
32
            return false;
33
        }
34
        return parent::hasInstance($alias);
35
    }
36
37
    public function destruct(): void
38
    {
39
        unset($this->container);
40
    }
41
}
42