Passed
Push — master ( b38d15...6f30ed )
by Luiz Kim
02:36
created

ProductGroup::setProductParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
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 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...
7
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...
8
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...
9
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...
10
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...
11
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...
12
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...
13
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...
14
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...
15
use 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...
16
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...
17
use Doctrine\ORM\Mapping\OneToMany;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\Mapping\OneToMany 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
19
/**
20
 * ProductGroup
21
 *
22
 * @ORM\Table(name="product_group")
23
 * @ORM\Entity(repositoryClass="ControleOnline\Repository\ProductGroupRepository")
24
 */
25
26
#[ApiResource(
27
    operations: [
28
        new Get(security: 'is_granted(\'ROLE_ADMIN\') or is_granted(\'ROLE_CLIENT\')'),
29
        new Put(
30
            security: 'is_granted(\'ROLE_CLIENT\')',
31
            denormalizationContext: ['groups' => ['product_group:write']]
32
        ),
33
        new Delete(security: 'is_granted(\'ROLE_CLIENT\')'),
34
        new Post(securityPostDenormalize: 'is_granted(\'ROLE_CLIENT\')'),
35
        new GetCollection(security: 'is_granted(\'ROLE_ADMIN\') or is_granted(\'ROLE_CLIENT\')')
36
    ],
37
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => ['text/csv']],
38
    normalizationContext: ['groups' => ['product_group:read']],
39
    denormalizationContext: ['groups' => ['product_group:write']]
40
)]
41
class ProductGroup
42
{
43
    /**
44
     * @var int
45
     *
46
     * @ORM\Column(name="id", type="integer", nullable=false)
47
     * @ORM\Id
48
     * @ORM\GeneratedValue(strategy="IDENTITY")
49
     * @Groups({"product_group:read","product_group:write"})
50
     */
51
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['id' => 'exact'])]
52
    private $id;
53
54
    /**
55
     * @var string
56
     *
57
     * @ORM\Column(name="product_group", type="string", length=255, nullable=false)
58
     * @Groups({"product_group:read","product_group:write"})
59
     */
60
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productGroup' => 'exact'])]
61
62
    private $productGroup;
63
64
    /**
65
     * @var string
66
     *
67
     * @ORM\Column(name="price_calculation", type="string", length=0, nullable=false, options={"default"="'sum'"})
68
     * @Groups({"product_group:read","product_group:write"})
69
     */
70
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['priceCalculation' => 'exact'])]
71
72
    private $priceCalculation = 'sum';
73
74
    /**
75
     * @var bool
76
     *
77
     * @ORM\Column(name="required", type="boolean", nullable=false)
78
     * @Groups({"product_group:read","product_group:write"})
79
     */
80
    private $required = 0;
81
82
    /**
83
     * @var int|null
84
     *
85
     * @ORM\Column(name="minimum", type="integer", nullable=true, options={"default"="NULL"})
86
     * @Groups({"product_group:read","product_group:write"})
87
     */
88
    private $minimum = NULL;
89
90
    /**
91
     * @var int|null
92
     *
93
     * @ORM\Column(name="maximum", type="integer", nullable=true, options={"default"="NULL"})
94
     * @Groups({"product_group:read","product_group:write"})
95
     */
96
    private $maximum = NULL;
97
98
    /**
99
     * @var bool
100
     *
101
     * @ORM\Column(name="active", type="boolean", nullable=false, options={"default"="1"})
102
     * @Groups({"product_group:read","product_group:write"})
103
     */
104
    private $active = true;
105
106
    /**
107
     * @var int
108
     *
109
     * @ORM\Column(name="group_order", type="integer", nullable=false)
110
     * @Groups({"product_group:read","product_group:write"})
111
     */
112
113
    private $groupOrder = 0;
114
115
    /**
116
     * @var Collection|ProductGroupProduct[]
117
     *
118
     * @ORM\OneToMany(targetEntity="ProductGroupProduct", mappedBy="productGroup", orphanRemoval=true)
119
     * @Groups({"product_group:write"})
120
     */
121
    private $products;
122
123
    /**
124
     * @ORM\ManyToOne(targetEntity="ControleOnline\Entity\Product")
125
     * @ORM\JoinColumn(nullable=false)
126
     * @Groups({"product_group:read","product_group:write"})
127
     */
128
    #[ApiFilter(filterClass: SearchFilter::class, properties: ['productParent' => 'exact'])]
129
130
    private $productParent;
131
132
    public function __construct()
133
    {
134
        $this->products = new ArrayCollection();
135
    }
136
137
    /**
138
     * Get the value of id
139
     */
140
    public function getId(): int
141
    {
142
        return $this->id;
143
    }
144
145
    /**
146
     * Get the value of productGroup
147
     */
148
    public function getProductGroup(): string
149
    {
150
        return $this->productGroup;
151
    }
152
153
    /**
154
     * Set the value of productGroup
155
     */
156
    public function setProductGroup(string $productGroup): self
157
    {
158
        $this->productGroup = $productGroup;
159
160
        return $this;
161
    }
162
163
    /**
164
     * Get the value of priceCalculation
165
     */
166
    public function getPriceCalculation(): string
167
    {
168
        return $this->priceCalculation;
169
    }
170
171
    /**
172
     * Set the value of priceCalculation
173
     */
174
    public function setPriceCalculation(string $priceCalculation): self
175
    {
176
        $this->priceCalculation = $priceCalculation;
177
178
        return $this;
179
    }
180
181
    /**
182
     * Get the value of required
183
     */
184
    public function isRequired(): bool
185
    {
186
        return $this->required;
187
    }
188
189
    /**
190
     * Set the value of required
191
     */
192
    public function setRequired(bool $required): self
193
    {
194
        $this->required = $required;
195
196
        return $this;
197
    }
198
199
    /**
200
     * Get the value of minimum
201
     */
202
    public function getMinimum(): ?int
203
    {
204
        return (float) $this->minimum;
0 ignored issues
show
Bug Best Practice introduced by
The expression return (double)$this->minimum returns the type double which is incompatible with the type-hinted return integer|null.
Loading history...
205
    }
206
207
    /**
208
     * Set the value of minimum
209
     */
210
    public function setMinimum(?int $minimum): self
211
    {
212
        $this->minimum = $minimum;
213
214
        return $this;
215
    }
216
217
    /**
218
     * Get the value of maximum
219
     */
220
    public function getMaximum(): ?int
221
    {
222
        return (float) $this->maximum;
0 ignored issues
show
Bug Best Practice introduced by
The expression return (double)$this->maximum returns the type double which is incompatible with the type-hinted return integer|null.
Loading history...
223
    }
224
225
    /**
226
     * Set the value of maximum
227
     */
228
    public function setMaximum(?int $maximum): self
229
    {
230
        $this->maximum = $maximum;
231
232
        return $this;
233
    }
234
235
    /**
236
     * Get the value of active
237
     */
238
    public function isActive(): bool
239
    {
240
        return $this->active;
241
    }
242
243
    /**
244
     * Set the value of active
245
     */
246
    public function setActive(bool $active): self
247
    {
248
        $this->active = $active;
249
250
        return $this;
251
    }
252
253
    /**
254
     * Get the value of groupOrder
255
     */
256
    public function getGroupOrder(): int
257
    {
258
        return $this->groupOrder;
259
    }
260
261
    /**
262
     * Set the value of groupOrder
263
     */
264
    public function setGroupOrder(int $groupOrder): self
265
    {
266
        $this->groupOrder = $groupOrder;
267
268
        return $this;
269
    }
270
271
    public function getRequired(): ?bool
272
    {
273
        return $this->required;
274
    }
275
276
    public function getActive(): ?bool
277
    {
278
        return $this->active;
279
    }
280
281
    /**
282
     * @return Collection|ProductGroupProduct[]
283
     */
284
    public function getProducts(): Collection
285
    {
286
        return $this->products;
287
    }
288
289
    public function addProduct(ProductGroupProduct $product): self
290
    {
291
        if (!$this->products->contains($product)) {
292
            $this->products[] = $product;
293
            $product->setProductGroup($this);
294
        }
295
296
        return $this;
297
    }
298
299
    public function removeProduct(ProductGroupProduct $product): self
300
    {
301
        if ($this->products->removeElement($product)) {
302
            // set the owning side to null (unless already changed)
303
            if ($product->getProductGroup() === $this) {
304
                $product->setProductGroup(null);
305
            }
306
        }
307
308
        return $this;
309
    }
310
311
    /**
312
     * Get the value of productParent
313
     */
314
    public function getProductParent()
315
    {
316
        return $this->productParent;
317
    }
318
319
    /**
320
     * Set the value of productParent
321
     */
322
    public function setProductParent($productParent): self
323
    {
324
        $this->productParent = $productParent;
325
326
        return $this;
327
    }
328
}
329