Completed
Push — master ( 1e2100...b879f8 )
by Taosikai
14:23
created

ClassDefinition::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
/**
3
 * slince dependency injection library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Di;
7
8
class ClassDefinition
9
{
10
    /**
11
     * Class
12
     * @var string
13
     */
14
    protected $class;
15
16
    /**
17
     * Array of arguments
18
     * @var array
19
     */
20
    protected $arguments = [];
21
22
    /**
23
     * Array of setters
24
     * @var array
25
     */
26
    protected $calls = [];
27
28
    /**
29
     * Array of properties
30
     * @var array
31
     */
32
    protected $properties = [];
33
34
    public function __construct($class, array $arguments = [], array $calls = [], array $properties = [])
35
    {
36
        $this->class = $class;
37
        $this->arguments = $arguments;
38
        $this->calls = $calls;
39
        $this->properties = $properties;
40
    }
41
42
    /**
43
     * Sets a argument
44
     * @param int|string $indexOrName
45
     * @param mixed $argument
46
     * @return $this
47
     */
48
    public function setArgument($indexOrName, $argument)
49
    {
50
        $this->arguments[$indexOrName] = $argument;
51
        return $this;
52
    }
53
54
55
    /**
56
     * Sets array of arguments
57
     * @param array $arguments
58
     * @return $this
59
     */
60
    public function setArguments(array $arguments)
61
    {
62
        $this->arguments = $arguments;
63
        return $this;
64
    }
65
66
    /**
67
     * Gets all arguments of constructor
68
     * @return array
69
     */
70
    public function getArguments()
71
    {
72
        return $this->arguments;
73
    }
74
75
    /**
76
     * Gets the argument at the specified position of constructor
77
     * @param int|string $indexOrName
78
     * @return mixed
79
     */
80
    public function getArgument($indexOrName)
81
    {
82
        return isset($this->arguments[$indexOrName]) ? $this->arguments[$indexOrName] : null;
83
    }
84
85
    /**
86
     * Adds a setter
87
     * @param string $method
88
     * @param array $arguments
89
     * @return $this
90
     */
91
    public function setMethodCall($method, array $arguments)
92
    {
93
        $this->calls[$method] = $arguments;
94
        return $this;
95
    }
96
97
    /**
98
     * Sets array of setter
99
     * @param array $calls
100
     * @return $this
101
     */
102
    public function setMethodCalls(array $calls)
103
    {
104
        $this->calls = array_merge($this->calls, $calls);
105
        return $this;
106
    }
107
108
    /**
109
     * Gets all setter
110
     * @return array
111
     */
112
    public function getMethodCalls()
113
    {
114
        return $this->calls;
115
    }
116
117
    /**
118
     * Gets the parameters of one setter
119
     * @param string $method
120
     * @return array|null
121
     */
122
    public function getMethodCall($method)
123
    {
124
        return isset($this->calls[$method]) ? $this->calls[$method] : null;
125
    }
126
127
    /**
128
     * Gets all properties
129
     * @return array
130
     */
131
    public function getProperties()
132
    {
133
        return $this->properties;
134
    }
135
136
    /**
137
     * Gets the class
138
     * @return string
139
     */
140
    public function getClass()
141
    {
142
        return $this->class;
143
    }
144
145
    public static function build(ClassDefinition $definition, array $arguments)
0 ignored issues
show
Unused Code introduced by
The parameter $definition is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $arguments is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
    {
147
148
    }
149
}
150