Intervention::setCoordinates()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace SDIS62\Core\Ops\Entity;
4
5
use Datetime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use SDIS62\Core\Common\Entity\IdentityTrait;
8
9
class Intervention
10
{
11
    use IdentityTrait;
12
13
    /**
14
     * Précision sur le sinistre de l'intervention.
15
     *
16
     * @var string
17
     */
18
    protected $precision;
19
20
    /**
21
     * Observations.
22
     *
23
     * @var string
24
     */
25
    protected $observations;
26
27
    /**
28
     * L'intervention est elle importante ?
29
     *
30
     * @var bool
31
     */
32
    protected $important;
33
34
    /**
35
     * Date de création.
36
     *
37
     * @var Datetime
38
     */
39
    protected $created;
40
41
    /**
42
     * Date de mise à jour.
43
     *
44
     * @var Datetime
45
     */
46
    protected $updated;
47
48
    /**
49
     * Date de fin.
50
     *
51
     * @var Datetime
52
     */
53
    protected $ended;
54
55
    /**
56
     * Sinistre de l'intervention.
57
     *
58
     * @var SDIS62\Core\Ops\Entity\Sinistre
59
     */
60
    protected $sinistre;
61
62
    /**
63
     * Engagements sur l'intervention.
64
     *
65
     * @var SDIS62\Core\Ops\Entity\Engagement[]
66
     */
67
    protected $engagements;
68
69
    /**
70
     * Evenements particuliers de l'intervention.
71
     *
72
     * @var SDIS62\Core\Ops\Entity\Evenement[]
73
     */
74
    protected $evenements;
75
76
    /**
77
     * Coordonnées de l'intervention.
78
     *
79
     * @var SDIS62\Core\Ops\Entity\Coordinates
80
     */
81
    protected $coordinates;
82
83
    /**
84
     * Adresse de l'intervention.
85
     *
86
     * @var string
87
     */
88
    protected $address;
89
90
    /**
91
     * Commune ou se place l'intervention.
92
     *
93
     * @var SDIS62\Core\Ops\Entity\Commune
94
     */
95
    protected $commune;
96
97
    /**
98
     * Création d'une intervention.
99
     */
100
    public function __construct(Sinistre $sinistre)
101
    {
102
        $this->sinistre    = $sinistre;
0 ignored issues
show
Documentation Bug introduced by
It seems like $sinistre of type object<SDIS62\Core\Ops\Entity\Sinistre> is incompatible with the declared type object<SDIS62\Core\Ops\E...re\Ops\Entity\Sinistre> of property $sinistre.

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...
103
        $this->created     = new Datetime('NOW');
104
        $this->evenements  = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<SDI...\Ops\Entity\Evenement>> of property $evenements.

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...
105
        $this->engagements = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<SDI...Ops\Entity\Engagement>> of property $engagements.

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...
106
    }
107
108
    /**
109
     * Get the value of Précision sur le sinistre de l'intervention.
110
     *
111
     * @return string
112
     */
113
    public function getPrecision()
114
    {
115
        return $this->precision;
116
    }
117
118
    /**
119
     * Set the value of Précision sur le sinistre de l'intervention.
120
     *
121
     * @param string precision
122
     *
123
     * @return self
124
     */
125
    public function setPrecision($precision)
126
    {
127
        $this->precision = $precision;
128
129
        $this->setUpdated();
130
131
        return $this;
132
    }
133
134
    /**
135
     * Get the value of Observations.
136
     *
137
     * @return string
138
     */
139
    public function getObservations()
140
    {
141
        return $this->observations;
142
    }
143
144
    /**
145
     * Set the value of Observations.
146
     *
147
     * @param string observations
148
     *
149
     * @return self
150
     */
151
    public function setObservations($observations)
152
    {
153
        $this->observations = $observations;
154
155
        $this->setUpdated();
156
157
        return $this;
158
    }
159
160
    /**
161
     * Get the value of L'intervention est elle importante ?
162
     *
163
     * @return bool
164
     */
165
    public function isImportant()
166
    {
167
        return $this->important === true;
168
    }
169
170
    /**
171
     * Set the value of L'intervention est elle importante ?
172
     *
173
     * @param bool important
174
     *
175
     * @return self
176
     */
177
    public function setImportant($important = true)
178
    {
179
        $this->important = $important === true;
180
181
        $this->setUpdated();
182
183
        return $this;
184
    }
185
186
    /**
187
     * Get the value of Date de création.
188
     *
189
     * @return Datetime
190
     */
191
    public function getCreated()
192
    {
193
        return $this->created;
194
    }
195
196
    /**
197
     * Get the value of Date de mise à jour.
198
     *
199
     * @return Datetime|null
200
     */
201
    public function getUpdated()
202
    {
203
        return $this->updated;
204
    }
205
206
    /**
207
     * Set the value of Date de mise à jour (la date doit être supérieure à la date de création).
208
     *
209
     * @param Datetime|string updated Format d-m-Y H:i:s
210
     *
211
     * @return self
212
     */
213
    public function setUpdated($updated = null)
214
    {
215
        if (empty($updated)) {
216
            $this->setUpdated(new Datetime());
217
        } else {
218
            $updated = $updated instanceof Datetime ? $updated : DateTime::createFromFormat('d-m-Y H:i:s', (string) $updated);
219
        }
220
221
        if ($updated > $this->created) {
222
            $this->updated = $updated;
223
        }
224
225
        return $this;
226
    }
227
228
    /**
229
     * Get the value of Date de fin.
230
     *
231
     * @return Datetime|null
232
     */
233
    public function getEnded()
234
    {
235
        return $this->ended;
236
    }
237
238
    /**
239
     * Set the value of Date de fin (la date doit être supérieure à la date de création et de mise à jour)
240
     * Met fin à tous les engagements.
241
     *
242
     * @param Datetime|string ended Format d-m-Y H:i:s
243
     *
244
     * @return self
245
     */
246
    public function setEnded($ended)
247
    {
248
        $ended = $ended instanceof Datetime ? $ended : DateTime::createFromFormat('d-m-Y H:i:s', (string) $ended);
249
250
        if ($ended > $this->created && (empty($this->updated) || $ended >= $this->updated)) {
251
            $this->ended = $ended;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ended can also be of type false. However, the property $ended is declared as type object<DateTime>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
252
253
            foreach ($this->engagements as $engagement) {
254
                $engagement->setEnded($ended);
255
            }
256
257
            $this->setUpdated();
258
        }
259
260
        return $this;
261
    }
262
263
    /**
264
     * Retourne vrai si l'intervention est terminée.
265
     *
266
     * @return bool
267
     */
268
    public function isEnded()
269
    {
270
        return !empty($this->ended);
271
    }
272
273
    /**
274
     * Get the value of Sinistre de l'intervention.
275
     *
276
     * @return SDIS62\Core\Ops\Entity\Sinistre
277
     */
278
    public function getSinistre()
279
    {
280
        return $this->sinistre;
281
    }
282
283
    /**
284
     * Set the value of Sinistre de l'intervention.
285
     *
286
     * @param SDIS62\Core\Ops\Entity\Sinistre sinistre
287
     *
288
     * @return self
289
     */
290
    public function setSinistre(Sinistre $sinistre)
291
    {
292
        $this->sinistre = $sinistre;
0 ignored issues
show
Documentation Bug introduced by
It seems like $sinistre of type object<SDIS62\Core\Ops\Entity\Sinistre> is incompatible with the declared type object<SDIS62\Core\Ops\E...re\Ops\Entity\Sinistre> of property $sinistre.

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...
293
294
        $this->setUpdated();
295
296
        return $this;
297
    }
298
299
    /**
300
     * Get the value of Engagements sur l'intervention.
301
     *
302
     * @return SDIS62\Core\Ops\Entity\Engagement[]
303
     */
304
    public function getEngagements()
305
    {
306
        return $this->engagements;
307
    }
308
309
    /**
310
     * Ajoute un engagement à l'intervention.
311
     *
312
     * @param SDIS62\Core\Ops\Entity\Engagement $engagement
313
     *
314
     * @return self
315
     */
316
    public function addEngagement(Engagement $engagement)
317
    {
318
        $this->engagements[] = $engagement;
319
320
        $this->setUpdated();
321
322
        return $this;
323
    }
324
325
    /**
326
     * Get the value of Evenements particuliers de l'intervention.
327
     *
328
     * @return SDIS62\Core\Ops\Entity\Evenement[]
329
     */
330
    public function getEvenements()
331
    {
332
        if (count($this->evenements) == 0) {
333
            return [];
334
        }
335
336
        $evenements = $this->evenements->toArray();
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $this->evenements (of type array<integer,object<SDI...\Ops\Entity\Evenement>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
337
338
        @usort($evenements, function ($a, $b) {
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
339
            return $a->getDate()->format('U') > $b->getDate()->format('U') ? -1 : 1;
340
        });
341
342
        return $evenements;
343
    }
344
345
    /**
346
     * Ajoute un evenement à l'intervention.
347
     *
348
     * @param SDIS62\Core\Ops\Entity\Evenement $evenement
349
     *
350
     * @return self
351
     */
352
    public function addEvenement(Evenement $evenement)
353
    {
354
        $this->evenements[] = $evenement;
355
356
        $this->setUpdated();
357
358
        return $this;
359
    }
360
361
    /**
362
     * Get the value of Coordonnées de l'intervention.
363
     *
364
     * @return SDIS62\Core\Ops\Entity\Coordinates
365
     */
366
    public function getCoordinates()
367
    {
368
        return $this->coordinates;
369
    }
370
371
    /**
372
     * Set the value of Coordonnées de l'intervention.
373
     *
374
     * @param SDIS62\Core\Ops\Entity\Coordinates $coordinates
375
     *
376
     * @return self
377
     */
378
    public function setCoordinates(Coordinates $coordinates)
379
    {
380
        $this->coordinates = $coordinates;
0 ignored issues
show
Documentation Bug introduced by
It seems like $coordinates of type object<SDIS62\Core\Ops\Entity\Coordinates> is incompatible with the declared type object<SDIS62\Core\Ops\E...Ops\Entity\Coordinates> of property $coordinates.

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...
381
382
        $this->setUpdated();
383
384
        return $this;
385
    }
386
387
    /**
388
     * Get the value of Adresse de l'intervention.
389
     *
390
     * @return string
391
     */
392
    public function getAddress()
393
    {
394
        return $this->address;
395
    }
396
397
    /**
398
     * Set the value of Adresse de l'intervention.
399
     *
400
     * @param string address
401
     *
402
     * @return self
403
     */
404
    public function setAddress($address)
405
    {
406
        $this->address = $address;
407
408
        $this->setUpdated();
409
410
        return $this;
411
    }
412
413
    /**
414
     * Get the value of Commune ou se place l'intervention.
415
     *
416
     * @return SDIS62\Core\Ops\Entity\Commune
417
     */
418
    public function getCommune()
419
    {
420
        return $this->commune;
421
    }
422
423
    /**
424
     * Set the value of Commune ou se place l'intervention.
425
     *
426
     * @param SDIS62\Core\Ops\Entity\Commune commune
427
     *
428
     * @return self
429
     */
430
    public function setCommune(Commune $commune)
431
    {
432
        $this->commune = $commune;
0 ignored issues
show
Documentation Bug introduced by
It seems like $commune of type object<SDIS62\Core\Ops\Entity\Commune> is incompatible with the declared type object<SDIS62\Core\Ops\E...ore\Ops\Entity\Commune> of property $commune.

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...
433
434
        $this->setUpdated();
435
436
        return $this;
437
    }
438
}
439