Completed
Push — SF4 ( f28f6b...15ccd7 )
by Laurent
04:33
created

Article::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Entity Article.
5
 *
6
 * PHP Version 7
7
 *
8
 * @author    Quétier Laurent <[email protected]>
9
 * @copyright 2018 Dev-Int GLSR
10
 * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
11
 *
12
 * @version GIT: $Id$
13
 *
14
 * @link https://github.com/Dev-Int/glsr
15
 */
16
namespace App\Entity\Settings;
17
18
use Doctrine\ORM\Mapping as ORM;
19
use Symfony\Component\Validator\Constraints as Assert;
20
use Gedmo\Mapping\Annotation as Gedmo;
21
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
22
use Doctrine\Common\Collections\ArrayCollection;
23
24
use App\Entity\Settings\Supplier;
25
use App\Entity\Settings\Diverse\Unit;
26
use App\Entity\Settings\Diverse\Tva;
27
use App\Entity\Settings\Diverse\FamilyLog;
28
use App\Entity\Settings\Diverse\ZoneStorage;
29
30
/**
31
 * Article.
32
 *
33
 * @category Entity
34
 *
35
 * @ORM\Table(name="app_article")
36
 * @ORM\Entity(repositoryClass="App\Repository\Settings\ArticleRepository")
37
 * @UniqueEntity(fields="name", message="This article name is already used.")
38
 * @ORM\HasLifecycleCallbacks()
39
 */
40
class Article
41
{
42
    /**
43
     * @var int Id of the article
44
     *
45
     * @ORM\Column(name="id", type="integer")
46
     * @ORM\Id
47
     * @ORM\GeneratedValue(strategy="AUTO")
48
     */
49
    private $id;
50
51
    /**
52
     * @var string title of the article
53
     *
54
     * @ORM\Column(name="name", type="string", length=255)
55
     * @Assert\NotBlank()
56
     * @Assert\Regex(
57
     *     pattern="'^\w+[^/]'",
58
     *     message="The title can only contain letters,
59
     * digits and _ or -"
60
     * )
61
     */
62
    private $name;
63
64
    /**
65
     * @var string|\App\Entity\Settings\Supplier Name of supplier
66
     *
67
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Supplier")
68
     */
69
    private $supplier;
70
71
    /**
72
     * @var string|\App\Entity\Settings\Diverse\Unit Storage unit
73
     *
74
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Diverse\Unit")
75
     */
76
    private $unitStorage;
77
78
    /**
79
     * @var string|\App\Entity\Settings\Diverse\Unit Working unit
80
     *
81
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Diverse\Unit")
82
     */
83
    private $unitWorking;
84
85
    /**
86
     * @var double Packaging (quantity)
87
     *
88
     * @ORM\Column(name="packaging", type="decimal", precision=7, scale=3)
89
     * @Assert\Type(type="numeric",
90
     * message="The value {{value}} is not a valid type {{type}}.")
91
     */
92
    private $packaging;
93
94
    /**
95
     * @var double price of the article
96
     *
97
     * @ORM\Column(name="price", type="decimal", precision=7, scale=3)
98
     * @Assert\Type(type="numeric",
99
     * message="The value {{value}} is not a valid type {{type}}.")
100
     */
101
    private $price;
102
103
    /**
104
     * @var string|\App\Entity\Settings\Diverse\Tva VAT rate
105
     *
106
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Diverse\Tva")
107
     */
108
    private $tva;
109
110
    /**
111
     * @var double Quantity in stock
112
     *
113
     * @ORM\Column(name="quantity", type="decimal", precision=7, scale=3, nullable=true, options={"default":0})
114
     * @Assert\Type(type="numeric",
115
     * message="The value {{value}} is not a valid type {{type}}.")
116
     */
117
    private $quantity;
118
119
    /**
120
     * @var double Minimum stock
121
     *
122
     * @ORM\Column(name="minstock", type="decimal", precision=7, scale=3)
123
     * @Assert\Type(type="numeric",
124
     * message="The value {{value}} is not a valid type {{type}}.")
125
     */
126
    private $minstock;
127
128
    /**
129
     * @var \Doctrine\Common\Collections\ArrayCollection Storage area (s)
130
     *
131
     * @ORM\ManyToMany(targetEntity="App\Entity\Settings\Diverse\ZoneStorage")
132
     * @ORM\JoinTable(name="app_article_zonestorage")
133
     * @Assert\NotBlank()
134
     */
135
    private $zoneStorages;
136
137
    /**
138
     * @var string|\App\Entity\Settings\Diverse\FamilyLog Logistic family
139
     *
140
     * @ORM\ManyToOne(targetEntity="App\Entity\Settings\Diverse\FamilyLog")
141
     * @Assert\NotBlank()
142
     */
143
    private $familyLog;
144
145
    /**
146
     * @var bool On / Off
147
     *
148
     * @ORM\Column(name="active", type="boolean")
149
     */
150
    private $active;
151
152
    /**
153
     * @Gedmo\Slug(fields={"name"}, updatable=false)
154
     * @ORM\Column(length=128, unique=true)
155
     */
156
    private $slug;
157
158
    /**
159
     * @var \DateTime Created date
160
     * @ORM\Column(name="create_at", type="datetime")
161
     */
162
    private $createAt;
163
164
    /**
165
     * @var \DateTime Updated date
166
     * @ORM\Column(name="update_at", type="datetime")
167
     */
168
    private $updateAt;
169
170
    /**
171
     * @var \DateTime Deleted date
172
     * @ORM\Column(name="delete_at", type="datetime", nullable=true)
173
     */
174
    private $deleteAt;
175
176
    /**
177
     * Constructor.
178
     */
179
    public function __construct()
180
    {
181
        $this->zoneStorages = new ArrayCollection();
182
        $this->active = true;
183
        $this->quantity = 0.000;
184
        $this->createAt = new \DateTime() ;
185
        $this->updateAt = new \DateTime() ;
186
        $this->deleteAt = new \DateTime('3000-12-31') ;
187
    }
188
189
    /**
190
     * Get id.
191
     *
192
     * @return int
193
     */
194
    public function getId()
195
    {
196
        return $this->id;
197
    }
198
199
    /**
200
     * Set name.
201
     *
202
     * @param string $name Article name
203
     *
204
     * @return Article
205
     */
206
    public function setName($name)
207
    {
208
        $this->name = $name;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Get name.
215
     *
216
     * @return string
217
     */
218
    public function getName()
219
    {
220
        return $this->name;
221
    }
222
223
    /**
224
     * Set packaging.
225
     *
226
     * @param double $packaging Packaging (quantity)
227
     *
228
     * @return Article
229
     */
230
    public function setPackaging($packaging)
231
    {
232
        $this->packaging = $packaging;
233
234
        return $this;
235
    }
236
237
    /**
238
     * Get packaging.
239
     *
240
     * @return double
241
     */
242
    public function getPackaging()
243
    {
244
        return $this->packaging;
245
    }
246
247
    /**
248
     * Set price.
249
     *
250
     * @param double $price price of the article
251
     *
252
     * @return Article
253
     */
254
    public function setPrice($price)
255
    {
256
        $this->price = $price;
257
258
        return $this;
259
    }
260
261
    /**
262
     * Get price.
263
     *
264
     * @return double
265
     */
266
    public function getPrice()
267
    {
268
        return $this->price;
269
    }
270
271
    /**
272
     * Set quantity.
273
     *
274
     * @param double $quantity quantity in stock
275
     *
276
     * @return Article
277
     */
278
    public function setQuantity($quantity)
279
    {
280
        $this->quantity = $quantity;
281
282
        return $this;
283
    }
284
285
    /**
286
     * Get quantity.
287
     *
288
     * @return double
289
     */
290
    public function getQuantity()
291
    {
292
        return $this->quantity;
293
    }
294
295
    /**
296
     * Set minstock.
297
     *
298
     * @param double $minstock Minimum stock
299
     *
300
     * @return Article
301
     */
302
    public function setMinstock($minstock)
303
    {
304
        $this->minstock = $minstock;
305
306
        return $this;
307
    }
308
309
    /**
310
     * Get minstock.
311
     *
312
     * @return double
313
     */
314
    public function getMinstock()
315
    {
316
        return $this->minstock;
317
    }
318
319
    /**
320
     * Set supplier.
321
     *
322
     * @param null|\App\Entity\Settings\Supplier $supplier Supplier of the article
323
     *
324
     * @return Article
325
     */
326
    public function setSupplier(Supplier $supplier = null)
327
    {
328
        $this->supplier = $supplier;
329
330
        return $this;
331
    }
332
333
    /**
334
     * Get supplier.
335
     *
336
     * @return string|\App\Entity\Settings\Supplier
337
     */
338
    public function getSupplier()
339
    {
340
        return $this->supplier;
341
    }
342
343
    /**
344
     * Set unitStorage.
345
     *
346
     * @param null|\App\Entity\Settings\Diverse\Unit $unitStorage Storage unit
347
     *
348
     * @return Article
349
     */
350
    public function setUnitStorage(Unit $unitStorage = null)
351
    {
352
        $this->unitStorage = $unitStorage;
353
354
        return $this;
355
    }
356
357
    /**
358
     * Get unitStorage.
359
     *
360
     * @return string|\App\Entity\Settings\Diverse\Unit
361
     */
362
    public function getUnitStorage()
363
    {
364
        return $this->unitStorage;
365
    }
366
367
    /**
368
     * Add zoneStorage.
369
     *
370
     * @param \App\Entity\Settings\Diverse\ZoneStorage
371
     * $zoneStorages Stockage area (s)
372
     *
373
     * @return Article
374
     */
375
    public function addZoneStorage(ZoneStorage $zoneStorages)
376
    {
377
        $this->zoneStorages[] = $zoneStorages;
378
379
        return $this;
380
    }
381
382
    /**
383
     * Remove zoneStorage.
384
     *
385
     * @param \App\Entity\Settings\Diverse\ZoneStorage $zoneStorages Storage area to delete
386
     *
387
     * @return \Doctrine\Common\Collections\ArrayCollection|null
388
     */
389
    public function removeZoneStorage(ZoneStorage $zoneStorages)
390
    {
391
        $this->zoneStorages->removeElement($zoneStorages);
392
    }
393
394
    /**
395
     * Get zoneStorage.
396
     *
397
     * @return \Doctrine\Common\Collections\ArrayCollection
398
     */
399
    public function getZoneStorages()
400
    {
401
        return $this->zoneStorages;
402
    }
403
404
    /**
405
     * Set unitWorking
406
     *
407
     * @param \App\Entity\Settings\Diverse\Unit $unitWorking
408
     * @return Article
409
     */
410
    public function setUnitWorking(Unit $unitWorking = null)
411
    {
412
        $this->unitWorking = $unitWorking;
413
414
        return $this;
415
    }
416
417
    /**
418
     * Get unitWorking
419
     *
420
     * @return \App\Entity\Settings\Diverse\UnitWorking
421
     */
422
    public function getUnitWorking()
423
    {
424
        return $this->unitWorking;
425
    }
426
427
    /**
428
     * Set familyLog.
429
     *
430
     * @param null|\App\Entity\Settings\Diverse\FamilyLog $familyLog Logistic family
431
     *
432
     * @return Article
433
     */
434
    public function setFamilyLog(FamilyLog $familyLog = null)
435
    {
436
        $this->familyLog = $familyLog;
437
438
        return $this;
439
    }
440
441
    /**
442
     * Get familyLog.
443
     *
444
     * @return \App\Entity\Settings\Diverse\FamilyLog
445
     */
446
    public function getFamilyLog()
447
    {
448
        return $this->familyLog;
449
    }
450
451
    /**
452
     * Set tva
453
     *
454
     * @param \App\Entity\Settings\Diverse\Tva $tva
455
     * @return Article
456
     */
457
    public function setTva(Tva $tva = null)
458
    {
459
        $this->tva = $tva;
460
461
        return $this;
462
    }
463
464
    /**
465
     * Get tva
466
     *
467
     * @return \App\Entity\Settings\Diverse\Tva
468
     */
469
    public function getTva()
470
    {
471
        return $this->tva;
472
    }
473
474
    /**
475
     * Set active.
476
     *
477
     * @param bool $active On / Off
478
     *
479
     * @return Article
480
     */
481
    public function setActive($active)
482
    {
483
        $this->active = $active;
484
485
        return $this;
486
    }
487
488
    /**
489
     * Is active
490
     *
491
     * @return boolean
492
     */
493
    public function isActive()
494
    {
495
        return $this->active;
496
    }
497
498
    /**
499
     * Get slug
500
     *
501
     * @return string
502
     */
503
    public function getSlug()
504
    {
505
        return $this->slug;
506
    }
507
508
    /**
509
     * This method allows to make "echo $article".
510
     * <p> So, to "show" $article,
511
     * PHP will actually show the return of this method. <br />
512
     * Here, the name, so "echo $article"
513
     * is equivalent to "echo $article->getName()". </p>
514
     *
515
     * @return string name
516
     */
517
    public function __toString()
518
    {
519
        return $this->name;
520
    }
521
522
    public function setSlug(string $slug): self
523
    {
524
        $this->slug = $slug;
525
526
        return $this;
527
    }
528
529
    /**
530
     * Get Create at
531
     *
532
     * @return \DateTimeInterface
533
     */
534
    public function getCreateAt()
535
    {
536
        return $this->createAt;
537
    }
538
539
    public function setCreateAt(\DateTimeInterface $createAt): self
540
    {
541
        $this->createAt = $createAt;
0 ignored issues
show
Documentation Bug introduced by
$createAt is of type object<DateTimeInterface>, but the property $createAt was declared to be of type object<DateTime>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
542
543
        return $this;
544
    }
545
546
    /**
547
     * Get Update at
548
     *
549
     * @return \DateTimeInterface
550
     */
551
    public function getUpdateAt()
552
    {
553
        return $this->updateAt;
554
    }
555
556
    public function setUpdateAt(\DateTimeInterface $updateAt): self
557
    {
558
        $this->updateAt = $updateAt;
0 ignored issues
show
Documentation Bug introduced by
$updateAt is of type object<DateTimeInterface>, but the property $updateAt was declared to be of type object<DateTime>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
559
560
        return $this;
561
    }
562
563
    /**
564
     * Get Delete at
565
     *
566
     * @return \DateTimeInterface
567
     */
568
    public function getDeleteAt()
569
    {
570
        return $this->updateAt;
571
    }
572
573
    public function setDeleteAt(\DateTimeInterface $deleteAt = null): self
574
    {
575
        if ($deleteAt == null) {
576
            $this->deleteAt = new \DateTime();
577
            date_date_set($this->deleteAt, date('Y') + 4, 12, 31);
578
        } else {
579
            $this->deleteAt = $deleteAt;
0 ignored issues
show
Documentation Bug introduced by
$deleteAt is of type object<DateTimeInterface>, but the property $deleteAt was declared to be of type object<DateTime>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
580
        }
581
582
        return $this;
583
    }
584
}
585