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

NullObjectDependency::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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