Issues (94)

src/di/NullObjectDependency.php (1 issue)

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
    /**
19
     * @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...
20
     */
21
    public function __construct(private string $interface)
22
    {
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function __toString(): string
29
    {
30
        return '';
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function inject(Container $container): null
37
    {
38
        return null;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function register(array &$container, Bind $bind): void
45
    {
46
        $container[(string) $bind] = $bind->getBound();
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function setScope($scope): void
53
    {
54
    }
55
56
    public function toNull(string $scriptDir): Dependency
57
    {
58
        assert(is_dir($scriptDir));
59
        $nullObject = new NullObject();
60
        $class = $nullObject->save($this->interface, $scriptDir);
61
62
        return new Dependency(new NewInstance(new ReflectionClass($class), new SetterMethods([])));
63
    }
64
}
65