Completed
Push — 2.x ( 144798...0daeb2 )
by Akihito
10s
created

Instance::__toString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 0
crap 3
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 81
    public function __construct($value)
19
    {
20 81
        $this->value = $value;
21 81
    }
22
23 1
    public function __toString()
24
    {
25 1
        if (is_scalar($this->value)) {
26 1
            return sprintf(
27 1
                '(%s) %s',
28 1
                gettype($this->value),
29 1
                (string) $this->value
30
            );
31
        }
32
33 1
        if (is_object($this->value)) {
34 1
            return '(object) ' . get_class($this->value);
35
        }
36
37 1
        return '(' . gettype($this->value) . ')';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 81
    public function register(array &$container, Bind $bind)
44
    {
45 81
        $index = (string) $bind;
46 81
        $container[$index] = $bind->getBound();
47 81
    }
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