1
|
|
|
<?php namespace Comodojo\Extender\Task; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Foundation\Logging\LoggerTrait; |
4
|
|
|
use \Comodojo\Foundation\Events\EventsTrait; |
5
|
|
|
use \Comodojo\Foundation\Base\ConfigurationTrait; |
6
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
7
|
|
|
use \Comodojo\Foundation\Events\Manager as EventsManager; |
8
|
|
|
use \Psr\Log\LoggerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @package Comodojo Extender |
12
|
|
|
* @author Marco Giovinazzi <[email protected]> |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* LICENSE: |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class TaskItem { |
28
|
|
|
|
29
|
|
|
use ConfigurationTrait; |
30
|
|
|
use EventsTrait; |
31
|
|
|
use LoggerTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $name; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $class; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
protected $description; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* TaskItem Constructor |
50
|
|
|
* |
51
|
|
|
* @param string $name |
52
|
|
|
* @param string $class |
53
|
|
|
* @param string $description |
54
|
|
|
*/ |
55
|
|
|
public function __construct( |
56
|
|
|
Configuration $configuration, |
57
|
|
|
EventsManager $events, |
58
|
|
|
LoggerInterface $logger, |
59
|
|
|
$name, |
60
|
|
|
$class, |
61
|
|
|
$description = null |
62
|
|
|
) { |
63
|
|
|
|
64
|
|
|
$this->setConfiguration($configuration); |
65
|
|
|
$this->setEvents($events); |
66
|
|
|
$this->setLogger($logger); |
67
|
|
|
|
68
|
|
|
$this->name = $name; |
69
|
|
|
$this->class = $class; |
70
|
|
|
$this->description = $description; |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getName() { |
79
|
|
|
|
80
|
|
|
return $this->name; |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* |
86
|
|
|
* @param string $name |
87
|
|
|
* @return TaskItem |
88
|
|
|
*/ |
89
|
|
|
public function setName($name) { |
90
|
|
|
|
91
|
|
|
$this->name = $name; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getClass() { |
102
|
|
|
|
103
|
|
|
return $this->class; |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* |
109
|
|
|
* @param string $class |
110
|
|
|
* @return TaskItem |
111
|
|
|
*/ |
112
|
|
|
public function setClass($class) { |
113
|
|
|
|
114
|
|
|
$this->class = $class; |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getDescription() { |
125
|
|
|
|
126
|
|
|
return $this->description; |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* |
132
|
|
|
* @param string $description |
133
|
|
|
* @return TaskItem |
134
|
|
|
*/ |
135
|
|
|
public function setDescription($description) { |
136
|
|
|
|
137
|
|
|
$this->description = $description; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getInstance($name, TaskParameters $parameters = null) { |
144
|
|
|
|
145
|
|
|
$task_class = $this->getClass(); |
146
|
|
|
|
147
|
|
|
if ( $parameters === null ) $parameters = new TaskParameters(); |
148
|
|
|
|
149
|
|
|
return new $task_class( |
150
|
|
|
$this->getConfiguration(), |
151
|
|
|
$this->getEvents(), |
152
|
|
|
$this->getLogger(), |
153
|
|
|
$name, |
154
|
|
|
$parameters === null ? new TaskParameters() : $parameters |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Static constructor |
161
|
|
|
* |
162
|
|
|
* @param string $name |
163
|
|
|
* @param string $class |
164
|
|
|
* @param string $description |
165
|
|
|
* @return TaskItem |
166
|
|
|
*/ |
167
|
|
|
public static function create($name, $class, $description = null) { |
168
|
|
|
|
169
|
|
|
return new TaskItem($name, $class, $description); |
|
|
|
|
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
} |
174
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.