Passed
Push — visitor ( 2d5566 )
by Akihito
11:02
created

Instance::accept()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di;
6
7
use Ray\Compiler\CompileVisitor;
0 ignored issues
show
Bug introduced by
The type Ray\Compiler\CompileVisitor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
use function assert;
10
use function get_class;
11
use function gettype;
12
use function is_object;
13
use function is_scalar;
14
use function sprintf;
15
16
final class Instance implements DependencyInterface
17
{
18
    /** @var mixed */
19
    public $value;
20
21
    /**
22
     * @param mixed $value
23
     */
24
    public function __construct($value)
25
    {
26
        $this->value = $value;
27
    }
28
29
    public function __toString(): string
30
    {
31
        if (is_scalar($this->value)) {
32
            return sprintf(
33
                '(%s) %s',
34
                gettype($this->value),
35
                (string) $this->value
36
            );
37
        }
38
39
        if (is_object($this->value)) {
40
            return '(object) ' . get_class($this->value);
41
        }
42
43
        return '(' . gettype($this->value) . ')';
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function register(array &$container, Bind $bind): void
50
    {
51
        $index = (string) $bind;
52
        $container[$index] = $bind->getBound();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function inject(Container $container)
59
    {
60
        return $this->value;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     *
66
     * @codeCoverageIgnore
67
     */
68
    public function setScope($scope): void
69
    {
70
    }
71
72
    public function accept(VisitorInterface $visitor): string
73
    {
74
        assert($visitor instanceof CompileVisitor);
75
76
        return $visitor->visitInstance($this->value);
0 ignored issues
show
Bug introduced by
The method visitInstance() does not exist on Ray\Di\VisitorInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        return $visitor->/** @scrutinizer ignore-call */ visitInstance($this->value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
    }
78
}
79