Completed
Push — master ( 1feeef...279c4f )
by Matthieu
8s
created

ArrayDefinition::__toString()   B

Complexity

Conditions 4
Paths 5

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 22
Code Lines 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 5
nop 0
dl 0
loc 22
rs 8.9197
1
<?php
2
3
namespace DI\Definition;
4
5
use DI\Definition\Helper\DefinitionHelper;
6
use DI\Scope;
7
8
/**
9
 * Definition of an array containing values or references.
10
 *
11
 * @since 5.0
12
 * @author Matthieu Napoli <[email protected]>
13
 */
14
class ArrayDefinition implements Definition
15
{
16
    /**
17
     * Entry name.
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var array
24
     */
25
    private $values;
26
27
    /**
28
     * @param string $name   Entry name
29
     * @param array  $values
30
     */
31
    public function __construct($name, array $values)
32
    {
33
        $this->name = $name;
34
        $this->values = $values;
35
    }
36
37
    /**
38
     * @return string Entry name
39
     */
40
    public function getName()
41
    {
42
        return $this->name;
43
    }
44
45
    /**
46
     * [email protected]}
47
     */
48
    public function getScope()
49
    {
50
        return Scope::SINGLETON;
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    public function getValues()
57
    {
58
        return $this->values;
59
    }
60
61
    public function __toString()
62
    {
63
        $str = '[' . PHP_EOL;
64
65
        foreach ($this->values as $key => $value) {
66
            if (is_string($key)) {
67
                $key = "'" . $key . "'";
68
            }
69
70
            $str .= '    ' . $key . ' => ';
71
72
            if ($value instanceof DefinitionHelper) {
73
                $str .= str_replace(PHP_EOL, PHP_EOL . '    ', $value->getDefinition(''));
74
            } else {
75
                $str .= var_export($value, true);
76
            }
77
78
            $str .= ',' . PHP_EOL;
79
        }
80
81
        return $str . ']';
82
    }
83
}
84