Completed
Pull Request — 1.0 (#8)
by David
02:19
created

ContainerDefinition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIdentifier() 0 4 1
A toPhpCode() 0 4 1
1
<?php
2
3
namespace TheCodingMachine\Yaco\ServiceProvider;
4
5
use TheCodingMachine\Yaco\Definition\DumpableInterface;
6
use TheCodingMachine\Yaco\Definition\InlineEntry;
7
use TheCodingMachine\Yaco\Definition\InlineEntryInterface;
8
9
/**
10
 * A definition that points to "$this" container.
11
 */
12
class ContainerDefinition implements DumpableInterface
13
{
14
    /**
15
     * The identifier of the instance in the container.
16
     *
17
     * @var string|null
18
     */
19
    private $identifier;
20
21
    /**
22
     * @param null|string $identifier
23
     */
24
    public function __construct($identifier = null)
25
    {
26
        $this->identifier = $identifier;
27
    }
28
29
    /**
30
     * Returns the identifier for this object in the container.
31
     * If null, classes consuming this definition should assume the definition must be inlined.
32
     *
33
     * @return string|null
34
     */
35
    public function getIdentifier()
36
    {
37
        return $this->identifier;
38
    }
39
40
    /**
41
     * Returns an InlineEntryInterface object representing the PHP code necessary to generate
42
     * the container entry.
43
     *
44
     * @param string $containerVariable The name of the variable that allows access to the container instance. For instance: "$container", or "$this->container"
45
     * @param array  $usedVariables     An array of variables that are already used and that should not be used when generating this code.
46
     *
47
     * @return InlineEntryInterface
48
     */
49
    public function toPhpCode($containerVariable, array $usedVariables = array())
50
    {
51
        return new InlineEntry($containerVariable, null, $usedVariables);
52
    }
53
}
54