Completed
Push — master ( 7e918b...fc4c54 )
by Matthieu
10s
created

InstanceDefinition::__toString()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
1
<?php
2
3
namespace DI\Definition;
4
5
use DI\Scope;
6
7
/**
8
 * Defines injections on an existing class instance.
9
 *
10
 * @since  5.0
11
 * @author Matthieu Napoli <[email protected]>
12
 */
13
class InstanceDefinition implements Definition
14
{
15
    /**
16
     * Instance on which to inject dependencies.
17
     *
18
     * @var object
19
     */
20
    private $instance;
21
22
    /**
23
     * @var ObjectDefinition
24
     */
25
    private $objectDefinition;
26
27
    /**
28
     * @param object $instance
29
     */
30
    public function __construct($instance, ObjectDefinition $objectDefinition)
31
    {
32
        $this->instance = $instance;
33
        $this->objectDefinition = $objectDefinition;
34
    }
35
36
    public function getName() : string
37
    {
38
        // Name are superfluous for instance definitions
39
        return '';
40
    }
41
42
    public function getScope() : string
43
    {
44
        return Scope::PROTOTYPE;
45
    }
46
47
    /**
48
     * @return object
49
     */
50
    public function getInstance()
51
    {
52
        return $this->instance;
53
    }
54
55
    public function getObjectDefinition() : ObjectDefinition
56
    {
57
        return $this->objectDefinition;
58
    }
59
60
    public function __toString()
61
    {
62
        return 'Instance';
63
    }
64
}
65