Completed
Pull Request — 2.x (#237)
by Akihito
01:34
created

NullObjectDependency   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 54
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 4 1
A inject() 0 4 1
A register() 0 4 1
A setScope() 0 3 1
A toNull() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Koriym\NullObject\NullObject;
8
use Ray\Di\Annotation\ScriptDir;
9
use ReflectionClass;
10
11
use function assert;
12
use function class_exists;
13
use function interface_exists;
14
use function is_dir;
15
use function is_string;
16
17
/**
18
 * @codeCoverageIgnore
19
 */
20
final class NullObjectDependency implements DependencyInterface
21
{
22
    /** @var class-string */
23
    private $interface;
24
25
    /**
26
     * @param class-string $interface
0 ignored issues
show
Documentation introduced by
The doc-type class-string could not be parsed: Unknown type name "class-string" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
27
     */
28
    public function __construct(string $interface)
29
    {
30
        $this->interface = $interface;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function __toString(): string
37
    {
38
        return '';
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function inject(Container $container)
45
    {
46
        return null;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @return void
53
     */
54
    public function register(array &$container, Bind $bind)
55
    {
56
        $container[(string) $bind] = $bind->getBound();
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function setScope($scope)
63
    {
64
    }
65
66
    public function toNull(string $scriptDir): Dependency
67
    {
68
        assert(is_dir($scriptDir));
69
        $nullClass = (new NullObject($scriptDir))($this->interface);
70
71
        return new Dependency(new NewInstance(new ReflectionClass($nullClass), new SetterMethods([])));
72
    }
73
}
74