Reference::getTarget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\Yaco\Definition;
4
5
/**
6
 * A reference to a service.
7
 */
8
class Reference implements ReferenceInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $target;
14
15
    /**
16
     * Constructs a Reference object targeting the $target entry.
17
     *
18
     * @param string $target
19
     */
20
    public function __construct($target)
21
    {
22
        $this->target = $target;
23
    }
24
25
    /**
26
     * Returns the identifier for the object in the container.
27
     *
28
     * @return string
29
     */
30
    public function getTarget()
31
    {
32
        return $this->target;
33
    }
34
35
    /**
36
     * Returns an InlineEntryInterface object representing the PHP code necessary to generate
37
     * the container entry.
38
     *
39
     * @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container"
40
     * @param array  $usedVariables     An array of variables that are already used and that should not be used when generating this code.
41
     *
42
     * @return InlineEntryInterface
43
     */
44
    public function toPhpCode($containerVariable, array $usedVariables = array())
45
    {
46
        return new InlineEntry(sprintf('%s->get(%s)', $containerVariable, var_export($this->getTarget(), true)), null, $usedVariables);
47
    }
48
}
49