Passed
Push — master ( 831821...2deebc )
by Luiz Kim
04:15 queued 02:07
created

Product::getParentProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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
#[ApiResource(
29
    operations: [
30
        new Get(security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')'),
31
        new Put(security: 'is_granted(\'ROLE_CLIENT\')', denormalizationContext: ['groups' => ['product:write']]),
32
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
33
        new Post(securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')'),
34
        new GetCollection(security: 'is_granted(\'IS_AUTHENTICATED_ANONYMOUSLY\')'),
35
    ],
36
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']],
37
    normalizationContext: ['groups' => ['product:read']],
38
    denormalizationContext: ['groups' => ['product:write']]
39
)]
40
#[ApiFilter(OrderFilter::class, properties: ['id' => 'ASC', 'product' => 'ASC', 'price' => 'DESC'])]
41
#[ApiFilter(RandomOrderFilter::class)]
42
class Product
43
{
44
    /**
45
     * @var int
46
     * @ORM\Column(name="id", type="integer", nullable=false)
47
     * @ORM\Id
48
     * @ORM\GeneratedValue(strategy="IDENTITY")
49
     * @Groups({"product_category:read","product:read","order_product:read"})
50
     */
51
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['id' => 'exact'])]
52
    private $id;
53
54
    /**
55
     * @var string
56
     * @ORM\Column(name="product", type="string", length=255, nullable=false)
57
     * @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"})
58
     */
59
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['product' => 'partial'])]
60
    private $product;
61
62
    /**
63
     * @ORM\OneToMany(targetEntity="ProductFile", mappedBy="product")
64
     * @Groups({"product:read","product_category:read"})
65
     */
66
    #[ApiFilter(filterClass: ExistsFilter::class, properties: ['productFiles'])]
67
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productFiles.file.fileType' => 'exact'])]
68
    private $productFiles;
69
70
    /**
71
     * @ORM\OneToMany(targetEntity="ProductCategory", mappedBy="product")
72
     */
73
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productCategory.category' => 'exact'])]
74
    private $productCategory;
75
76
    /**
77
     * @var string|null
78
     * @ORM\Column(name="sku", type="string", length=32, nullable=true, options={"default"="NULL"})
79
     * @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"})
80
     */
81
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['sku' => 'partial'])]
82
    private $sku = null;
83
84
    /**
85
     * @var string
86
     * @ORM\Column(name="type", type="string", length=0, nullable=false, options={"default"="'product'"})
87
     * @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"})
88
     */
89
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['type' => 'exact'])]
90
    private $type = 'product';
91
92
    /**
93
     * @var float
94
     * @ORM\Column(name="price", type="float", precision=10, scale=0, nullable=false)
95
     * @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"})
96
     */
97
    private $price = 0;
98
99
    /**
100
     * @var string
101
     * @ORM\Column(name="product_condition", type="string", length=0, nullable=false, options={"default"="'new'"})
102
     * @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"})
103
     */
104
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productCondition' => 'exact'])]
105
    private $productCondition = 'new';
106
107
    /**
108
     * @var string
109
     * @ORM\Column(name="description", type="string", length=0, nullable=false)
110
     * @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"})
111
     */
112
    private $description = '';
113
114
    /**
115
     * @var bool
116
     * @ORM\Column(name="featured", type="boolean", nullable=false, options={"default"="0"})
117
     * @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"})
118
     */
119
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['featured' => 'exact'])]
120
    private $featured = false;
121
122
    /**
123
     * @var bool
124
     * @ORM\Column(name="active", type="boolean", nullable=false, options={"default"="1"})
125
     * @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"})
126
     */
127
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['active' => 'exact'])]
128
    private $active = true;
129
130
    /**
131
     * @var \ControleOnline\Entity\People
132
     * @ORM\ManyToOne(targetEntity="\ControleOnline\Entity\People")
133
     * @ORM\JoinColumns({
134
     *   @ORM\JoinColumn(name="company_id", referencedColumnName="id")
135
     * })
136
     * @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"})
137
     */
138
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['company' => 'exact'])]
139
    private $company;
140
141
    /**
142
     * @var ProductUnity
143
     * @ORM\ManyToOne(targetEntity="ProductUnity")
144
     * @ORM\JoinColumns({
145
     *   @ORM\JoinColumn(name="product_unit_id", referencedColumnName="id")
146
     * })
147
     * @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"})
148
     */
149
    private $productUnit;
150
151
    /**
152
     * @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...
153
     * @ORM\ManyToOne(targetEntity="Queue")
154
     * @ORM\JoinColumns({
155
     *   @ORM\JoinColumn(name="queue_id", referencedColumnName="id")
156
     * })
157
     * @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"})
158
     */
159
    private $queue;
160
161
    /**
162
     * @var Collection|Product[]
163
     * @ORM\OneToMany(targetEntity="Product", mappedBy="parentProduct")
164
     * @Groups({"product_group_product:read"})
165
     */
166
    private $childProducts;
167
168
    /**
169
     * @var Product|null
170
     * @ORM\ManyToOne(targetEntity="Product", inversedBy="childProducts")
171
     * @ORM\JoinColumn(name="parent_product_id", referencedColumnName="id", nullable=true)
172
     * @Groups({"product:read", "product:write"})
173
     */
174
    private $parentProduct;
175
176
    public function __construct()
177
    {
178
        $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...
179
        $this->productCategory = new \Doctrine\Common\Collections\ArrayCollection();
180
        $this->childProducts = new \Doctrine\Common\Collections\ArrayCollection();
181
    }
182
183
    public function getId(): int
184
    {
185
        return $this->id;
186
    }
187
188
    public function setId(int $id): self
189
    {
190
        $this->id = $id;
191
        return $this;
192
    }
193
194
    public function getProduct(): string
195
    {
196
        return $this->product;
197
    }
198
199
    public function setProduct(string $product): self
200
    {
201
        $this->product = $product;
202
        return $this;
203
    }
204
205
    public function getSku(): ?string
206
    {
207
        return $this->sku;
208
    }
209
210
    public function setSku(?string $sku): self
211
    {
212
        $this->sku = $sku;
213
        return $this;
214
    }
215
216
    public function getType(): string
217
    {
218
        return $this->type;
219
    }
220
221
    public function setType(string $type): self
222
    {
223
        $this->type = $type;
224
        return $this;
225
    }
226
227
    public function getPrice(): float
228
    {
229
        return $this->price;
230
    }
231
232
    public function setPrice(float $price): self
233
    {
234
        $this->price = $price;
235
        return $this;
236
    }
237
238
    public function getProductCondition(): string
239
    {
240
        return $this->productCondition;
241
    }
242
243
    public function setProductCondition(string $productCondition): self
244
    {
245
        $this->productCondition = $productCondition;
246
        return $this;
247
    }
248
249
    public function isActive(): bool
250
    {
251
        return $this->active;
252
    }
253
254
    public function setActive(bool $active): self
255
    {
256
        $this->active = $active;
257
        return $this;
258
    }
259
260
    public function getCompany(): ?People
261
    {
262
        return $this->company;
263
    }
264
265
    public function setCompany(People $company): self
266
    {
267
        $this->company = $company;
268
        return $this;
269
    }
270
271
    public function getProductUnit(): ProductUnity
272
    {
273
        return $this->productUnit;
274
    }
275
276
    public function setProductUnit(ProductUnity $productUnit): self
277
    {
278
        $this->productUnit = $productUnit;
279
        return $this;
280
    }
281
282
    public function getDescription(): string
283
    {
284
        return $this->description;
285
    }
286
287
    public function setDescription(string $description): self
288
    {
289
        $this->description = $description;
290
        return $this;
291
    }
292
293
    public function getQueue()
294
    {
295
        return $this->queue;
296
    }
297
298
    public function setQueue($queue): self
299
    {
300
        $this->queue = $queue;
301
        return $this;
302
    }
303
304
    public function getProductFiles(): Collection
305
    {
306
        return $this->productFiles;
307
    }
308
309
    public function getProductCategory(): Collection
310
    {
311
        return $this->productCategory;
312
    }
313
314
    public function getFeatured(): bool
315
    {
316
        return $this->featured;
317
    }
318
319
    public function setFeatured(bool $featured): self
320
    {
321
        $this->featured = $featured;
322
        return $this;
323
    }
324
325
    public function getChildProducts(): Collection
326
    {
327
        return $this->childProducts;
328
    }
329
330
    public function addChildProduct(Product $childProduct): self
331
    {
332
        if (!$this->childProducts->contains($childProduct)) {
333
            $this->childProducts->add($childProduct);
334
            $childProduct->setParentProduct($this);
335
        }
336
        return $this;
337
    }
338
339
    public function removeChildProduct(Product $childProduct): self
340
    {
341
        if ($this->childProducts->removeElement($childProduct)) {
342
            if ($childProduct->getParentProduct() === $this) {
343
                $childProduct->setParentProduct(null);
344
            }
345
        }
346
        return $this;
347
    }
348
349
    public function getParentProduct(): ?Product
350
    {
351
        return $this->parentProduct;
352
    }
353
354
    public function setParentProduct(?Product $parentProduct): self
355
    {
356
        $this->parentProduct = $parentProduct;
357
        return $this;
358
    }
359
}