NullObjectDependency::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
c 1
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Koriym\NullObject\NullObject;
8
use ReflectionClass;
9
10
use function assert;
11
use function is_dir;
12
13
/**
14
 * @codeCoverageIgnore
15
 */
16
final class NullObjectDependency implements DependencyInterface
17
{
18
    /** @var class-string */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
19
    private $interface;
20
21
    /**
22
     * @param class-string $interface
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
23
     */
24
    public function __construct(string $interface)
25
    {
26
        $this->interface = $interface;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function __toString(): string
33
    {
34
        return '';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function inject(Container $container)
41
    {
42
        return null;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     *
48
     * @return void
49
     */
50
    public function register(array &$container, Bind $bind)
51
    {
52
        $container[(string) $bind] = $bind->getBound();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function setScope($scope)
59
    {
60
    }
61
62
    public function toNull(string $scriptDir): Dependency
63
    {
64
        assert(is_dir($scriptDir));
65
        $nullObject = new NullObject();
66
        $class = $nullObject->save($this->interface, $scriptDir);
67
68
        return new Dependency(new NewInstance(new ReflectionClass($class), new SetterMethods([])));
69
    }
70
}
71