Issues (144)

src/Comodojo/Extender/Orm/Entities/Worklog.php (5 issues)

1
<?php namespace Comodojo\Extender\Orm\Entities;
2
3
use \Doctrine\ORM\Mapping as ORM;
4
use \Comodojo\Extender\Traits\BaseEntityTrait;
5
use \Comodojo\Extender\Task\TaskParameters;
6
use \InvalidArgumentException;
7
use \DateTime;
8
9
/**
10
 * @package     Comodojo Extender
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @license     MIT
13
 *
14
 * LICENSE:
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 *
24
 * @ORM\Table(name="extender_worklog")
25
 * @ORM\Entity
26
 */
27
class Worklog {
28
29
    const STATUS_RUN = 0;
30
31
    const STATUS_ERROR = 1;
32
33
    const STATUS_COMPLETE = 2;
34
35
    const STATUS_ABORT = 3;
36
37
    use BaseEntityTrait;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(name="uid", type="string", length=128, nullable=false)
43
     */
44
    protected $uid;
45
46
    /**
47
     * @var integer
48
     *
49
     * @ORM\Column(name="pid", type="integer", nullable=false)
50
     */
51
    protected $pid;
52
53
    /**
54
     * @var integer
55
     *
56
     * @ORM\ManyToOne(targetEntity="Schedule", cascade={"persist"})
57
     * @ORM\JoinColumn(name="jid", nullable=true, referencedColumnName="id", onDelete="SET NULL")
58
     */
59
    protected $jid;
60
61
    /**
62
     * @var integer
63
     *
64
     * @ORM\Column(name="parentuid", type="string", nullable=true)
65
     */
66
    protected $parent_uid;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(name="task", type="string", length=256, nullable=false)
72
     */
73
    protected $task;
74
75
    /**
76
     * @var string
77
     *
78
     * @ORM\Column(name="parameters", type="array", nullable=false)
79
     */
80
    protected $parameters = [];
81
82
    /**
83
     * @var integer
84
     *
85
     * @ORM\Column(name="status", type="integer", nullable=false)
86
     */
87
    protected $status;
88
89
    /**
90
     * @var string
91
     *
92
     * @ORM\Column(name="result", type="text", length=65535, nullable=true)
93
     */
94
    protected $result;
95
96
    /**
97
     * @var datetime
98
     *
99
     * @ORM\Column(name="start", type="datetime", nullable=false)
100
     */
101
    protected $start_time;
102
103
    /**
104
     * @var datetime
105
     *
106
     * @ORM\Column(name="end", type="datetime", nullable=true)
107
     */
108
    protected $end_time;
109
110
    /**
111
     * Get worklog item's uid
112
     *
113
     * @return string
114
     */
115
    public function getUid() {
116
117
        return $this->uid;
118
119
    }
120
121
    /**
122
     * Set worklog item's uid
123
     *
124
     * @param string $uid
125
     * @return Worklog
126
     */
127
    public function setUid($uid) {
128
129
        $this->uid = $uid;
130
131
        return $this;
132
133
    }
134
135
    /**
136
     * Get worklog item's pid
137
     *
138
     * @return integer
139
     */
140
    public function getPid() {
141
142
        return $this->pid;
143
144
    }
145
146
    /**
147
     * Set worklog item's pid
148
     *
149
     * @param int $pid
150
     * @return Worklog
151
     */
152
    public function setPid($pid) {
153
154
        $this->pid = $pid;
155
156
        return $this;
157
158
    }
159
160
    /**
161
     * Get worklog item's jid
162
     *
163
     * @return integer
164
     */
165
    public function getJid() {
166
167
        return $this->jid;
168
169
    }
170
171
    /**
172
     * Set worklog item's jid
173
     *
174
     * @param Schedule $schedule
175
     * @return Worklog
176
     */
177
    public function setJid(Schedule $schedule) {
178
179
        $this->jid = $schedule;
0 ignored issues
show
Documentation Bug introduced by
It seems like $schedule of type Comodojo\Extender\Orm\Entities\Schedule is incompatible with the declared type integer of property $jid.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
180
181
        return $this;
182
183
    }
184
185
    /**
186
     * Get worklog item's parent
187
     *
188
     * @return strin
0 ignored issues
show
The type Comodojo\Extender\Orm\Entities\strin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
189
     */
190
    public function getParentUid() {
191
192
        return $this->parent_uid;
193
194
    }
195
196
    /**
197
     * Set worklog item's parent
198
     *
199
     * @param string $parent_uid
200
     * @return Worklog
201
     */
202
    public function setParentUid($parent_uid) {
203
204
        $this->parent_uid = $parent_uid;
0 ignored issues
show
Documentation Bug introduced by
The property $parent_uid was declared of type integer, but $parent_uid is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
205
206
        return $this;
207
208
    }
209
210
    /**
211
     * Get associated task
212
     *
213
     * @return string
214
     */
215
    public function getTask() {
216
217
        return $this->task;
218
219
    }
220
221
    /**
222
     * Set associated task
223
     *
224
     * @param string $task
225
     * @return Schedule
226
     */
227
    public function setTask($task) {
228
229
        $this->task = $task;
230
231
        return $this;
232
233
    }
234
235
    /**
236
     * Get queue item's parameters
237
     *
238
     * @return TaskParameters
239
     */
240
    public function getParameters() {
241
242
        return new TaskParameters($this->parameters);
0 ignored issues
show
$this->parameters of type string is incompatible with the type array expected by parameter $parameters of Comodojo\Extender\Task\T...rameters::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

242
        return new TaskParameters(/** @scrutinizer ignore-type */ $this->parameters);
Loading history...
243
244
    }
245
246
    /**
247
     * Set queue item's parameters
248
     *
249
     * @param TaskParameters $parameters
250
     * @return Schedule
251
     */
252
    public function setParameters(TaskParameters $parameters) {
253
254
        $this->parameters = $parameters->get();
0 ignored issues
show
Documentation Bug introduced by
It seems like $parameters->get() of type array is incompatible with the declared type string of property $parameters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
255
256
        return $this;
257
258
    }
259
260
    /**
261
     * Get current job status
262
     *
263
     * @return int
264
     */
265
    public function getStatus() {
266
267
        return $this->status;
268
269
    }
270
271
    /**
272
     * Set current job status
273
     *
274
     * @param string $name
275
     * @return Worklog
276
     */
277
    public function setStatus($status) {
278
279
        if ( !in_array($status, range(0, 3)) ) throw new InvalidArgumentException("Invalid status $status");
280
281
        $this->status = $status;
282
283
        return $this;
284
285
    }
286
287
    /**
288
     * Get the task's result
289
     *
290
     * @return string
291
     */
292
    public function getResult() {
293
294
        return unserialize($this->result);
295
296
    }
297
298
    /**
299
     * Set the task's result
300
     *
301
     * @param string $result
302
     * @return Worklog
303
     */
304
    public function setResult($result) {
305
306
        $this->result = serialize($result);
307
308
        return $this;
309
310
    }
311
312
    /**
313
     * Get the task's start-time
314
     *
315
     * @return DateTime
316
     */
317
    public function getStartTime() {
318
319
        return $this->start_time;
320
321
    }
322
323
    /**
324
     * Set the task's start-time
325
     *
326
     * @param DateTime $datetime
327
     * @return Worklog
328
     */
329
    public function setStartTime(DateTime $datetime) {
330
331
        $this->start_time = $datetime;
332
333
        return $this;
334
335
    }
336
337
    /**
338
     * Get the task's end-time
339
     *
340
     * @return DateTime
341
     */
342
    public function getEndTime() {
343
344
        return $this->end_time;
345
346
    }
347
348
    /**
349
     * Set the task's end-time
350
     *
351
     * @param DateTime $datetime
352
     * @return Worklog
353
     */
354
    public function setEndTime(DateTime $datetime) {
355
356
        $this->end_time = $datetime;
357
358
        return $this;
359
360
    }
361
362
}
363