Completed
Push — 2.x ( 07ed38...d68955 )
by Akihito
03:36
created

Instance::__toString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 0
crap 12
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the Ray.Di package.
6
 *
7
 * @license http://opensource.org/licenses/MIT MIT
8
 */
9
namespace Ray\Di;
10
11
final class Instance implements DependencyInterface
12
{
13
    /**
14
     * @var mixed
15
     */
16
    public $value;
17
18 79
    public function __construct($value)
19
    {
20 79
        $this->value = $value;
21 79
    }
22
23
    public function __toString()
24
    {
25
        if (is_scalar($this->value)) {
26
            return sprintf(
27
                '(%s) %s',
28
                gettype($this->value),
29
                (string) $this->value
30
            );
31
        }
32
33
        if (is_object($this->value)) {
34
            return '(object) ' . get_class($this->value);
35
        }
36
37
        return '(' . gettype($this->value) . ')';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 79
    public function register(array &$container, Bind $bind)
44
    {
45 79
        $index = (string) $bind;
46 79
        $container[$index] = $bind->getBound();
47 79
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 30
    public function inject(Container $container)
53
    {
54 30
        unset($container);
55
56 30
        return $this->value;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     *
62
     * @codeCoverageIgnore
63
     */
64
    public function setScope($scope)
65
    {
66
    }
67
}
68