Completed
Push — 2.x ( 8f6930...447f85 )
by Akihito
01:14
created

NullObjectDependency::setScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
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\Compiler\FilePutContents;
9
use Ray\Di\Annotation\ScriptDir;
10
use ReflectionClass;
11
12
use function assert;
13
use function class_exists;
14
use function interface_exists;
15
use function is_dir;
16
use function is_string;
17
use function sprintf;
18
use function str_replace;
19
20
/**
21
 * @codeCoverageIgnore
22
 */
23
final class NullObjectDependency implements DependencyInterface
24
{
25
    /** @var class-string */
26
    private $interface;
27
28
    /**
29
     * @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...
30
     */
31
    public function __construct(string $interface)
32
    {
33
        $this->interface = $interface;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function __toString(): string
40
    {
41
        return '';
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function inject(Container $container)
48
    {
49
        return null;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     *
55
     * @return void
56
     */
57
    public function register(array &$container, Bind $bind)
58
    {
59
        $container[(string) $bind] = $bind->getBound();
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setScope($scope)
66
    {
67
    }
68
69
    public function toNull(string $scriptDir): Dependency
70
    {
71
        assert(is_dir($scriptDir));
72
        $nullObject = new NullObject();
73
        $class = $nullObject->save($this->interface, $scriptDir);
74
75
        return new Dependency(new NewInstance(new ReflectionClass($class), new SetterMethods([])));
76
    }
77
}
78