Completed
Push — sf2.7 ( e6a060...c3d5ae )
by Laurent
03:05
created

Article::setSlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 * Entité Article.
5
 *
6
 * PHP Version 5
7
 *
8
 * @author     Quétier Laurent <[email protected]>
9
 * @copyright  2014 Dev-Int GLSR
10
 * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
11
 *
12
 * @version    since 1.0.0
13
 *
14
 * @link       https://github.com/Dev-Int/glsr
15
 */
16
namespace AppBundle\Entity;
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
use AppBundle\Entity\Supplier;
24
use AppBundle\Entity\UnitStorage;
25
use AppBundle\Entity\ZoneStorage;
26
use AppBundle\Entity\FamilyLog;
27
28
/**
29
 * Article.
30
 *
31
 * @category   Entity
32
 *
33
 * @ORM\Table(name="gs_article")
34
 * @ORM\Entity(repositoryClass="AppBundle\Entity\ArticleRepository")
35
 * @UniqueEntity(fields="name", message="Ce nom d'article est déjà utilisé.")
36
 * @ORM\HasLifecycleCallbacks()
37
 */
38
class Article
39
{
40
    /**
41
     * @var int Id de l'article
42
     *
43
     * @ORM\Column(name="id", type="integer")
44
     * @ORM\Id
45
     * @ORM\GeneratedValue(strategy="AUTO")
46
     */
47
    private $id;
48
49
    /**
50
     * @var string intitulé de l'article
51
     *
52
     * @ORM\Column(name="name", type="string", length=255)
53
     * @Assert\NotBlank()
54
     * @Assert\Regex(
55
     *     pattern="'^\w+[^/]'",
56
     *     message="L'intitulé ne peut contenir que des lettres,
57
     *     chiffres et _ ou -"
58
     * )
59
     */
60
    private $name;
61
62
    /**
63
     * @var string Nom du fournisseur
64
     *
65
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Supplier")
66
     */
67
    private $supplier;
68
69
    /**
70
     * @var string Unité de stockage
71
     *
72
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UnitStorage")
73
     */
74
    private $unit_storage;
75
76
    /**
77
     * @var decimal Conditionement (quantité)
78
     *
79
     * @ORM\Column(name="packaging", type="decimal", precision=7, scale=3)
80
     * @Assert\Type(type="numeric",
81
     * message="La valeur {{ value }} n'est pas un type {{ type }} valide.")
82
     */
83
    private $packaging;
84
85
    /**
86
     * @var decimal prix de l'article
87
     *
88
     * @ORM\Column(name="price", type="decimal", precision=7, scale=3)
89
     * @Assert\Type(type="numeric",
90
     * message="La valeur {{ value }} n'est pas un type {{ type }} valide.")
91
     */
92
    private $price;
93
94
    /**
95
     * @var decimal Quantité en stock
96
     *
97
     * @ORM\Column(name="quantity", type="decimal", precision=7, scale=3)
98
     * @Assert\Type(type="numeric",
99
     * message="La valeur {{ value }} n'est pas un type {{ type }} valide.")
100
     */
101
    private $quantity;
102
103
    /**
104
     * @var decimal Stock minimum
105
     *
106
     * @ORM\Column(name="minstock", type="decimal", precision=7, scale=3)
107
     * @Assert\Type(type="numeric",
108
     * message="La valeur {{ value }} n'est pas un type {{ type }} valide.")
109
     */
110
    private $minstock;
111
112
    /**
113
     * @var string Zone(s) de stockage
114
     *
115
     * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ZoneStorage")
116
     * @ORM\JoinTable(name="gs_article_zonestorage")
117
     * @Assert\NotBlank()
118
     */
119
    private $zone_storages;
120
121
    /**
122
     * @var string Famille logistique
123
     *
124
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\FamilyLog")
125
     * @Assert\NotBlank()
126
     */
127
    private $family_log;
128
129
    /**
130
     * @var bool Activé/Désactivé
131
     *
132
     * @ORM\Column(name="active", type="boolean")
133
     */
134
    private $active;
135
136
    /**
137
     * @Gedmo\Slug(fields={"name"}, updatable=false)
138
     * @ORM\Column(length=128, unique=true)
139
     */
140
    private $slug;
141
142
    /**
143
     * Constructor.
144
     */
145
    public function __construct()
146
    {
147
        $this->zone_storages = 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 string of property $zone_storages.

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...
148
        $this->active = true;
149
        $this->quantity = 0.000;
0 ignored issues
show
Documentation Bug introduced by
It seems like 0.0 of type double is incompatible with the declared type object<AppBundle\Entity\decimal> of property $quantity.

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...
150
    }
151
152
    /**
153
     * Get id.
154
     *
155
     * @return int
156
     */
157
    public function getId()
158
    {
159
        return $this->id;
160
    }
161
162
    /**
163
     * Set name.
164
     *
165
     * @param string $name Nom de l'article
166
     *
167
     * @return Article
168
     */
169
    public function setName($name)
170
    {
171
        $this->name = $name;
172
173
        return $this;
174
    }
175
176
    /**
177
     * Get name.
178
     *
179
     * @return string
180
     */
181
    public function getName()
182
    {
183
        return $this->name;
184
    }
185
186
    /**
187
     * Set packaging.
188
     *
189
     * @param string $packaging Conditionnement (quantité)
190
     *
191
     * @return Article
192
     */
193
    public function setPackaging($packaging)
194
    {
195
        $this->packaging = $packaging;
0 ignored issues
show
Documentation Bug introduced by
It seems like $packaging of type string is incompatible with the declared type object<AppBundle\Entity\decimal> of property $packaging.

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...
196
197
        return $this;
198
    }
199
200
    /**
201
     * Get packaging.
202
     *
203
     * @return string
204
     */
205
    public function getPackaging()
206
    {
207
        return $this->packaging;
208
    }
209
210
    /**
211
     * Set price.
212
     *
213
     * @param string $price prix de l'article
214
     *
215
     * @return Article
216
     */
217
    public function setPrice($price)
218
    {
219
        $this->price = $price;
0 ignored issues
show
Documentation Bug introduced by
It seems like $price of type string is incompatible with the declared type object<AppBundle\Entity\decimal> of property $price.

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...
220
221
        return $this;
222
    }
223
224
    /**
225
     * Get price.
226
     *
227
     * @return string
228
     */
229
    public function getPrice()
230
    {
231
        return $this->price;
232
    }
233
234
    /**
235
     * Set quantity.
236
     *
237
     * @param string $quantity quantité en stock
238
     *
239
     * @return Article
240
     */
241
    public function setQuantity($quantity)
242
    {
243
        $this->quantity = $quantity;
0 ignored issues
show
Documentation Bug introduced by
It seems like $quantity of type string is incompatible with the declared type object<AppBundle\Entity\decimal> of property $quantity.

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...
244
245
        return $this;
246
    }
247
248
    /**
249
     * Get quantity.
250
     *
251
     * @return string
252
     */
253
    public function getQuantity()
254
    {
255
        return $this->quantity;
256
    }
257
258
    /**
259
     * Set minstock.
260
     *
261
     * @param string $minstock stock minimum
262
     *
263
     * @return Article
264
     */
265
    public function setMinstock($minstock)
266
    {
267
        $this->minstock = $minstock;
0 ignored issues
show
Documentation Bug introduced by
It seems like $minstock of type string is incompatible with the declared type object<AppBundle\Entity\decimal> of property $minstock.

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...
268
269
        return $this;
270
    }
271
272
    /**
273
     * Get minstock.
274
     *
275
     * @return string
276
     */
277
    public function getMinstock()
278
    {
279
        return $this->minstock;
280
    }
281
282
    /**
283
     * Set supplier.
284
     *
285
     * @param Supplier $supplier Fournisseur de l'article
286
     *
287
     * @return Article
288
     */
289
    public function setSupplier(Supplier $supplier = null)
290
    {
291
        $this->supplier = $supplier;
0 ignored issues
show
Documentation Bug introduced by
It seems like $supplier can also be of type object<AppBundle\Entity\Supplier>. However, the property $supplier is declared as type string. 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...
292
293
        return $this;
294
    }
295
296
    /**
297
     * Get supplier.
298
     *
299
     * @return Supplier
300
     */
301
    public function getSupplier()
302
    {
303
        return $this->supplier;
304
    }
305
306
    /**
307
     * Set unit_storage.
308
     *
309
     * @param UnitStorage $unitStorage Unité de stockage
310
     *
311
     * @return Article
312
     */
313
    public function setUnitStorage(UnitStorage $unitStorage = null)
314
    {
315
        $this->unit_storage = $unitStorage;
0 ignored issues
show
Documentation Bug introduced by
It seems like $unitStorage can also be of type object<AppBundle\Entity\UnitStorage>. However, the property $unit_storage is declared as type string. 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...
316
317
        return $this;
318
    }
319
320
    /**
321
     * Get unit_storage.
322
     *
323
     * @return UnitStorage
324
     */
325
    public function getUnitStorage()
326
    {
327
        return $this->unit_storage;
328
    }
329
330
    /**
331
     * Add zone_storages.
332
     *
333
     * @param \AppBundle\Entity\ZoneStorage
334
     * $zoneStorages Zone(s) de stockage
335
     *
336
     * @return Article
337
     */
338
    public function addZoneStorage(ZoneStorage $zoneStorages)
339
    {
340
        $this->zone_storages[] = $zoneStorages;
341
342
        return $this;
343
    }
344
345
    /**
346
     * Remove zone_storages.
347
     *
348
     * @param ZoneStorage $zoneStorages Zone de stockage à supprimer
349
     *
350
     * @return \Doctrine\Common\Collections\Collection
351
     */
352
    public function removeZoneStorage(ZoneStorage $zoneStorages)
353
    {
354
        $this->zone_storages->removeElement($zoneStorages);
0 ignored issues
show
Bug introduced by
The method removeElement cannot be called on $this->zone_storages (of type string).

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...
355
    }
356
357
    /**
358
     * Get zone_storages.
359
     *
360
     * @return \Doctrine\Common\Collections\Collection
361
     */
362
    public function getZoneStorages()
363
    {
364
        return $this->zone_storages;
365
    }
366
367
    /**
368
     * Set family_log.
369
     *
370
     * @param FamilyLog $familyLog Famille Logistique
371
     *
372
     * @return Article
373
     */
374
    public function setFamilyLog(FamilyLog $familyLog = null)
375
    {
376
        $this->family_log = $familyLog;
0 ignored issues
show
Documentation Bug introduced by
It seems like $familyLog can also be of type object<AppBundle\Entity\FamilyLog>. However, the property $family_log is declared as type string. 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...
377
378
        return $this;
379
    }
380
381
    /**
382
     * Get family_log.
383
     *
384
     * @return FamilyLog
385
     */
386
    public function getFamilyLog()
387
    {
388
        return $this->family_log;
389
    }
390
391
    /**
392
     * Set active.
393
     *
394
     * @param bool $active Activé/Désactivé
395
     *
396
     * @return Article
397
     */
398
    public function setActive($active)
399
    {
400
        $this->active = $active;
401
402
        return $this;
403
    }
404
405
    /**
406
     * Is active
407
     *
408
     * @return boolean
409
     */
410
    public function isActive()
411
    {
412
        return $this->active;
413
    }
414
415
    /**
416
     * Get slug
417
     *
418
     * @return string
419
     */
420
    public function getSlug()
421
    {
422
        return $this->slug;
423
    }
424
425
    /**
426
     * Cette méthode permet de faire "echo $article".
427
     * <p>Ainsi, pour "afficher" $article,
428
     * PHP affichera en réalité le retour de cette méthode.<br />
429
     * Ici, le nom, donc "echo $article"
430
     * est équivalent à "echo $article->getName()".</p>
431
     *
432
     * @return string name
433
     */
434
    public function __toString()
435
    {
436
        return $this->name;
437
    }
438
}
439