Passed
Push — master ( 1a2a26...d606e3 )
by Luiz Kim
02:10
created

Product::getChildProducts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping 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...
6
use ControleOnline\Entity\People;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\People 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...
7
use ControleOnline\Entity\ProductUnity;
8
use Symfony\Component\Serializer\Annotation\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Annotation\Groups 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...
9
use ApiPlatform\Metadata\GetCollection;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\GetCollection 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...
10
use ApiPlatform\Metadata\Post;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Post 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...
11
use ApiPlatform\Metadata\Delete;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Delete 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...
12
use ApiPlatform\Metadata\Put;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Put 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...
13
use ApiPlatform\Metadata\Get;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Get 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...
14
use ApiPlatform\Metadata\ApiResource;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiResource 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...
15
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\SearchFilter 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...
16
use ApiPlatform\Doctrine\Orm\Filter\ExistsFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\ExistsFilter 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...
17
use ApiPlatform\Metadata\ApiFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\ApiFilter 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...
18
use Doctrine\Common\Collections\Collection;
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Collections\Collection 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...
19
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Doctrine\Orm\Filter\OrderFilter 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...
20
use ControleOnline\Filter\RandomOrderFilter;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Filter\RandomOrderFilter 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...
21
22
/**
23
 * Product
24
 *
25
 * @ORM\Table(name="product", uniqueConstraints={@ORM\UniqueConstraint(name="company_id", columns={"company_id", "sku"})}, indexes={@ORM\Index(name="product_unit_id", columns={"product_unit_id"}), @ORM\Index(name="IDX_D34A04AD979B1AD6", columns={"company_id"})})
26
 * @ORM\Entity(repositoryClass="ControleOnline\Repository\ProductRepository")
27
 */
28
29
#[ApiResource(
30
    operations: [
31
        new Get(
32
            security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
33
        ),
34
        new Put(
35
            security: 'is_granted(\'ROLE_CLIENT\')',
36
            denormalizationContext: ['groups' => ['product:write']]
37
        ),
38
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
39
        new Post(securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')'),
40
        new GetCollection(
41
            security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')',
42
        )
43
    ],
44
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']],
45
    normalizationContext: ['groups' => ['product:read']],
46
    denormalizationContext: ['groups' => ['product:write']]
47
)]
48
49
#[ApiFilter(OrderFilter::class, properties: ['id' => 'ASC', 'product' => 'ASC', 'price' => 'DESC'])]
50
#[ApiFilter(RandomOrderFilter::class)]
51
52
class Product
53
{
54
    /**
55
     * @var int
56
     *
57
     * @ORM\Column(name="id", type="integer", nullable=false)
58
     * @ORM\Id
59
     * @ORM\GeneratedValue(strategy="IDENTITY")
60
     * @Groups({"product_category:read","product:read","order_product:read"})
61
     */
62
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['id' => 'exact'])]
63
64
    private $id;
65
66
    /**
67
     * @var string
68
     *
69
     * @ORM\Column(name="product", type="string", length=255, nullable=false)
70
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
71
     */
72
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['product' => 'partial'])]
73
74
    private $product;
75
76
    /**
77
     * @ORM\OneToMany(targetEntity="ProductFile", mappedBy="product")
78
     * @Groups({"product:read","product_category:read"})
79
     */
80
    #[ApiFilter(filterClass: ExistsFilter::class, properties: ['productFiles'])]
81
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productFiles.file.fileType' => 'exact'])]
82
83
    private $productFiles;
84
85
    /**
86
     * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="product")
87
     */
88
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productCategory.category' => 'exact'])]
89
90
    private $productCategory;
91
92
    /**
93
     * @var string|null
94
     *
95
     * @ORM\Column(name="sku", type="string", length=32, nullable=true, options={"default"="NULL"})
96
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
97
     */
98
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['sku' => 'partial'])]
99
100
    private $sku = NULL;
101
102
    /**
103
     * @var string
104
     *
105
     * @ORM\Column(name="type", type="string", length=0, nullable=false, options={"default"="'product'"})
106
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
107
     */
108
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['type' => 'exact'])]
109
    private $type = 'product';
110
111
    /**
112
     * @var float
113
     *
114
     * @ORM\Column(name="price", type="float", precision=10, scale=0, nullable=false)
115
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
116
     */
117
    private $price = 0;
118
119
    /**
120
     * @var string
121
     *
122
     * @ORM\Column(name="product_condition", type="string", length=0, nullable=false, options={"default"="'new'"})
123
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
124
     */
125
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productCondition' => 'exact'])]
126
127
    private $productCondition = 'new';
128
129
130
    /**
131
     * @var string
132
     *
133
     * @ORM\Column(name="description", type="string", length=0, nullable=false)
134
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
135
     */
136
    private $description = '';
137
138
139
    /**
140
     * @var bool
141
     *
142
     * @ORM\Column(name="featured", type="boolean", nullable=false, options={"default"="0"})
143
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
144
     */
145
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['featured' => 'exact'])]
146
147
    private $featured = false;
148
149
    /**
150
     * @var bool
151
     *
152
     * @ORM\Column(name="active", type="boolean", nullable=false, options={"default"="1"})
153
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
154
     */
155
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['active' => 'exact'])]
156
157
    private $active = true;
158
159
    /**
160
     * @var \ControleOnline\Entity\People
161
     *
162
     * @ORM\ManyToOne(targetEntity="\ControleOnline\Entity\People")
163
     * @ORM\JoinColumns({
164
     *   @ORM\JoinColumn(name="company_id", referencedColumnName="id")
165
     * })
166
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
167
     */
168
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['company' => 'exact'])]
169
170
    private $company;
171
172
    /**
173
     * @var ProductUnity
174
     *
175
     * @ORM\ManyToOne(targetEntity="ProductUnity")
176
     * @ORM\JoinColumns({
177
     *   @ORM\JoinColumn(name="product_unit_id", referencedColumnName="id")
178
     * })
179
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
180
     */
181
    private $productUnit;
182
183
    /**
184
     * @var Queue
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Queue 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...
185
     *
186
     * @ORM\ManyToOne(targetEntity="Queue")
187
     * @ORM\JoinColumns({
188
     *   @ORM\JoinColumn(name="queue_id", referencedColumnName="id")
189
     * })
190
     * @Groups({"product_category:read","product:read","product_group_product:read","order_product:read","order_product_queue:read","order:read","order_details:read","order:write","product:write"})
191
     */
192
    private $queue;
193
194
    /**
195
     * @var Collection|Product[]
196
     *
197
     * @ORM\OneToMany(targetEntity="Product", mappedBy="parentProduct")
198
     * @Groups({"product_group_product:read"})
199
     */
200
    private $childProducts;
201
202
    public function __construct()
203
    {
204
        $this->productFiles = new \Doctrine\Common\Collections\ArrayCollection();
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Collections\ArrayCollection 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...
205
        $this->productCategory = new \Doctrine\Common\Collections\ArrayCollection();
206
        $this->childProducts = new \Doctrine\Common\Collections\ArrayCollection();
207
    }
208
209
    /**
210
     * Get the value of id
211
     */
212
    public function getId(): int
213
    {
214
        return $this->id;
215
    }
216
217
    /**
218
     * Set the value of id
219
     */
220
    public function setId(int $id): self
221
    {
222
        $this->id = $id;
223
224
        return $this;
225
    }
226
227
    /**
228
     * Get the value of product
229
     */
230
    public function getProduct(): string
231
    {
232
        return $this->product;
233
    }
234
235
    /**
236
     * Set the value of product
237
     */
238
    public function setProduct(string $product): self
239
    {
240
        $this->product = $product;
241
242
        return $this;
243
    }
244
245
    /**
246
     * Get the value of sku
247
     */
248
    public function getSku(): ?string
249
    {
250
        return $this->sku;
251
    }
252
253
    /**
254
     * Set the value of sku
255
     */
256
    public function setSku(?string $sku): self
257
    {
258
        $this->sku = $sku;
259
260
        return $this;
261
    }
262
263
    /**
264
     * Get the value of type
265
     */
266
    public function getType(): string
267
    {
268
        return $this->type;
269
    }
270
271
    /**
272
     * Set the value of type
273
     */
274
    public function setType(string $type): self
275
    {
276
        $this->type = $type;
277
278
        return $this;
279
    }
280
281
    /**
282
     * Get the value of price
283
     */
284
    public function getPrice(): float
285
    {
286
        return $this->price;
287
    }
288
289
    /**
290
     * Set the value of price
291
     */
292
    public function setPrice(float $price): self
293
    {
294
        $this->price = $price;
295
296
        return $this;
297
    }
298
299
    /**
300
     * Get the value of productCondition
301
     */
302
    public function getProductCondition(): string
303
    {
304
        return $this->productCondition;
305
    }
306
307
    /**
308
     * Set the value of productCondition
309
     */
310
    public function setProductCondition(string $productCondition): self
311
    {
312
        $this->productCondition = $productCondition;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get the value of active
319
     */
320
    public function isActive(): bool
321
    {
322
        return $this->active;
323
    }
324
325
    /**
326
     * Set the value of active
327
     */
328
    public function setActive(bool $active): self
329
    {
330
        $this->active = $active;
331
332
        return $this;
333
    }
334
335
    /**
336
     * Get the value of company
337
     */
338
    public function getCompany(): ?People
339
    {
340
        return $this->company;
341
    }
342
343
    /**
344
     * Set the value of company
345
     */
346
    public function setCompany(People $company): self
347
    {
348
        $this->company = $company;
349
350
        return $this;
351
    }
352
353
    /**
354
     * Get the value of productUnit
355
     */
356
    public function getProductUnit(): ProductUnity
357
    {
358
        return $this->productUnit;
359
    }
360
361
    /**
362
     * Set the value of productUnit
363
     */
364
    public function setProductUnit(ProductUnity $productUnit): self
365
    {
366
        $this->productUnit = $productUnit;
367
368
        return $this;
369
    }
370
371
    public function getActive(): ?bool
372
    {
373
        return $this->active;
374
    }
375
376
    /**
377
     * Get the value of description
378
     */
379
    public function getDescription()
380
    {
381
        return $this->description;
382
    }
383
384
    /**
385
     * Set the value of description
386
     */
387
    public function setDescription($description): self
388
    {
389
        $this->description = $description;
390
391
        return $this;
392
    }
393
394
    /**
395
     * Get the value of queue
396
     */
397
    public function getQueue()
398
    {
399
        return $this->queue;
400
    }
401
402
    /**
403
     * Set the value of queue
404
     */
405
    public function setQueue($queue): self
406
    {
407
        $this->queue = $queue;
408
409
        return $this;
410
    }
411
412
    /**
413
     * @return Collection|ProductFile[]
414
     */
415
    public function getProductFiles(): Collection
416
    {
417
        return $this->productFiles;
418
    }
419
420
    /**
421
     * @return Collection|ProductCategory[]
422
     */
423
    public function getProductCategory(): Collection
424
    {
425
        return $this->productCategory;
426
    }
427
428
    /**
429
     * Get the value of featured
430
     */
431
    public function getFeatured()
432
    {
433
        return $this->featured;
434
    }
435
436
    /**
437
     * Set the value of featured
438
     */
439
    public function setFeatured($featured): self
440
    {
441
        $this->featured = $featured;
442
443
        return $this;
444
    }
445
446
    public function getChildProducts(): Collection
447
{
448
    return $this->childProducts;
449
}
450
451
public function addChildProduct(Product $childProduct): self
452
{
453
    if (!$this->childProducts->contains($childProduct)) {
454
        $this->childProducts->add($childProduct);
455
        $childProduct->setParentProduct($this);
0 ignored issues
show
Bug introduced by
The method setParentProduct() does not exist on ControleOnline\Entity\Product. ( Ignorable by Annotation )

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

455
        $childProduct->/** @scrutinizer ignore-call */ 
456
                       setParentProduct($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
456
    }
457
    return $this;
458
}
459
460
public function removeChildProduct(Product $childProduct): self
461
{
462
    if ($this->childProducts->removeElement($childProduct)) {
463
        if ($childProduct->getParentProduct() === $this) {
0 ignored issues
show
Bug introduced by
The method getParentProduct() does not exist on ControleOnline\Entity\Product. ( Ignorable by Annotation )

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

463
        if ($childProduct->/** @scrutinizer ignore-call */ getParentProduct() === $this) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
464
            $childProduct->setParentProduct(null);
465
        }
466
    }
467
    return $this;
468
}
469
}
470