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

Binder::hasInjector()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 43
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 10.7998

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 43
ccs 16
cts 20
cp 0.8
rs 7.6666
cc 10
nc 7
nop 1
crap 10.7998

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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