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

MethodInjection::__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\ObjectDefinition;
4
5
use DI\Definition\Definition;
6
use DI\Scope;
7
8
/**
9
 * Describe an injection in an object method.
10
 *
11
 * @author Matthieu Napoli <[email protected]>
12
 */
13
class MethodInjection implements Definition
14
{
15
    /**
16
     * @var string
17
     */
18
    private $methodName;
19
20
    /**
21
     * @var array
22
     */
23
    private $parameters = [];
24
25
    public function __construct(string $methodName, array $parameters = [])
26
    {
27
        $this->methodName = (string) $methodName;
28
        $this->parameters = $parameters;
29
    }
30
31
    public static function constructor(array $parameters = [])
32
    {
33
        return new self('__construct', $parameters);
34
    }
35
36
    public function getMethodName() : string
37
    {
38
        return $this->methodName;
39
    }
40
41
    public function getParameters() : array
42
    {
43
        return $this->parameters;
44
    }
45
46
    /**
47
     * Replace the parameters of the definition by a new array of parameters.
48
     */
49
    public function replaceParameters(array $parameters)
50
    {
51
        $this->parameters = $parameters;
52
    }
53
54
    public function merge(MethodInjection $definition)
55
    {
56
        // In case of conflicts, the current definition prevails.
57
        $this->parameters = $this->parameters + $definition->parameters;
58
    }
59
60
    public function getName() : string
61
    {
62
        return '';
63
    }
64
65
    public function getScope() : string
66
    {
67
        return Scope::PROTOTYPE;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function __toString()
74
    {
75
        return sprintf('method(%s)', $this->methodName);
76
    }
77
}
78