Completed
Push — 2.x ( 590aac...5c2340 )
by Akihito
07:34 queued 03:49
created

Instance   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 60
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 16 3
A register() 0 5 1
A inject() 0 6 1
A setScope() 0 3 1
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
    /**
19
     * @param mixed $value
20
     */
21 80
    public function __construct($value)
22
    {
23 80
        $this->value = $value;
24 80
    }
25
26 1
    public function __toString()
27
    {
28 1
        if (is_scalar($this->value)) {
29 1
            return sprintf(
30 1
                '(%s) %s',
31 1
                gettype($this->value),
32 1
                (string) $this->value
33
            );
34
        }
35
36 1
        if (is_object($this->value)) {
37 1
            return '(object) ' . get_class($this->value);
38
        }
39
40 1
        return '(' . gettype($this->value) . ')';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 80
    public function register(array &$container, Bind $bind)
47
    {
48 80
        $index = (string) $bind;
49 80
        $container[$index] = $bind->getBound();
50 80
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 30
    public function inject(Container $container)
56
    {
57 30
        unset($container);
58
59 30
        return $this->value;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     *
65
     * @codeCoverageIgnore
66
     */
67
    public function setScope($scope)
68
    {
69
    }
70
}
71