Completed
Push — master ( 55a9c0...ed128c )
by Emil
14:56
created

QueuedTask::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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 2
nc 1
nop 1
1
<?php
2
3
namespace Glooby\TaskBundle\Model;
4
5
/**
6
 * @author Emil Kilhage
7
 */
8
class QueuedTask implements QueuedTaskInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $id;
14
15
    /**
16
     * @var string
17
     */
18
    protected $name;
19
20
    /**
21
     * @var \DateTime
22
     */
23
    protected $created;
24
25
    /**
26
     * @var array
27
     */
28
    protected $params = [];
29
30
    /**
31
     * @var ScheduleInterface
32
     */
33
    protected $schedule;
34
35
    /**
36
     * @var \DateTime
37
     */
38
    protected $executeAt;
39
40
    /**
41
     * @var \DateTime
42
     */
43
    protected $started;
44
45
    /**
46
     * @var \DateTime
47
     */
48
    protected $finished;
49
50
    /**
51
     * @var \DateTime
52
     */
53
    protected $result;
54
55
    /**
56
     * @var string
57
     */
58
    protected $status = self::STATUS_PENDING;
59
60
    /**
61
     * @var string
62
     */
63
    protected $resolution = self::RESOLUTION_PENDING;
64
65
    /**
66
     * QueuedTask constructor.
67
     */
68
    public function __construct()
69
    {
70
        $this->created = new \DateTime();
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getId(): int
77
    {
78
        return $this->id;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function setId(int $id)
85
    {
86
        $this->id = $id;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getName(): string
93
    {
94
        return $this->name;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function setName(string $name)
101
    {
102
        $this->name = $name;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getCreated(): \DateTime
109
    {
110
        return $this->created;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function setCreated(\DateTime $created)
117
    {
118
        $this->created = $created;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124
    public function getExecuteAt(): \DateTime
125
    {
126
        return $this->executeAt;
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132
    public function setExecuteAt(\DateTime $executeAt)
133
    {
134
        $this->executeAt = $executeAt;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function getSchedule(): ScheduleInterface
141
    {
142
        return $this->schedule;
143
    }
144
145
    /**
146
     * {@inheritdoc}
147
     */
148
    public function setSchedule(ScheduleInterface $schedule)
149
    {
150
        $this->schedule = $schedule;
151
    }
152
153
    /**
154
     * {@inheritdoc}
155
     */
156
    public function getParams(): array
157
    {
158
        return $this->params;
159
    }
160
161
    /**
162
     * {@inheritdoc}
163
     */
164
    public function hasParams(): bool
165
    {
166
        return count($this->params) > 0;
167
    }
168
169
    /**
170
     * {@inheritdoc}
171
     */
172
    public function setParams(array $params = null)
173
    {
174
        $this->params = $params;
0 ignored issues
show
Documentation Bug introduced by
It seems like $params can be null. However, the property $params is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
175
    }
176
177
    /**
178
     * {@inheritdoc}
179
     */
180
    public function getResult()
181
    {
182
        return $this->result;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->result; (DateTime) is incompatible with the return type declared by the interface Glooby\TaskBundle\Model\...askInterface::getResult of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
183
    }
184
185
    /**
186
     * {@inheritdoc}
187
     */
188
    public function setResult($result)
189
    {
190
        $this->result = $result;
0 ignored issues
show
Documentation Bug introduced by
It seems like $result of type string is incompatible with the declared type object<DateTime> of property $result.

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...
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function getResolution(): string
197
    {
198
        return $this->resolution;
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204
    public function setResolution(string $resolution)
205
    {
206
        $this->resolution = $resolution;
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212
    public function getFinished(): \DateTime
213
    {
214
        return $this->finished;
215
    }
216
217
    /**
218
     * {@inheritdoc}
219
     */
220
    public function setFinished(\DateTime $finished)
221
    {
222
        $this->finished = $finished;
223
    }
224
225
    /**
226
     * {@inheritdoc}
227
     */
228
    public function getStatus(): string
229
    {
230
        return $this->status;
231
    }
232
233
    /**
234
     * {@inheritdoc}
235
     */
236
    public function setStatus(string $status)
237
    {
238
        $this->status = $status;
239
    }
240
241
    /**
242
     * {@inheritdoc}
243
     */
244
    public function getStarted(): \DateTime
245
    {
246
        return $this->started;
247
    }
248
249
    /**
250
     * {@inheritdoc}
251
     */
252
    public function setStarted(\DateTime $started)
253
    {
254
        $this->started = $started;
255
    }
256
}
257