Passed
Push — master ( b73a64...9b2d66 )
by Luiz Kim
02:21
created

Task::getOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ControleOnline\Entity;
4
5
use Symfony\Component\Serializer\Attribute\Groups;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Serializer\Attribute\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...
6
7
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...
8
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...
9
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...
10
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...
11
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...
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\Patch;
0 ignored issues
show
Bug introduced by
The type ApiPlatform\Metadata\Patch 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\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...
15
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...
16
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...
17
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...
18
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...
19
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...
20
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...
21
use ControleOnline\Entity\Status;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Status 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...
22
use ControleOnline\Entity\Category;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Category 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...
23
use ControleOnline\Entity\Order;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Order 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...
24
use ControleOnline\Repository\TaskRepository;
25
use ControleOnline\Listener\LogListener;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Listener\LogListener 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...
26
use DateTime;
27
use DateTimeInterface;
28
use stdClass;
29
30
#[ORM\Table(name: 'tasks')]
31
#[ORM\EntityListeners([LogListener::class])]
32
#[ORM\Entity(repositoryClass: TaskRepository::class)]
33
#[ApiResource(
34
    formats: ['jsonld', 'json', 'html', 'jsonhal', 'csv' => 'text/csv'],
35
    normalizationContext: ['groups' => ['task:read']],
36
    denormalizationContext: ['groups' => ['task:write']],
37
    security: "is_granted('ROLE_CLIENT')",
38
    operations: [
39
        new GetCollection(
40
            security: "is_granted('ROLE_CLIENT')",
41
            uriTemplate: '/tasks'
42
        ),
43
        new Get(security: "is_granted('ROLE_CLIENT')"),
44
        new Post(security: "is_granted('ROLE_CLIENT')"),
45
        new Put(security: "is_granted('ROLE_CLIENT')"),
46
        new Patch(security: "is_granted('ROLE_CLIENT')"),
47
        new Delete(security: "is_granted('ROLE_CLIENT')")
48
    ]
49
)]
50
#[ApiFilter(OrderFilter::class, properties: ['dueDate' => 'ASC', 'alterDate' => 'DESC'])]
51
#[ApiFilter(SearchFilter::class, properties: [
52
    'provider' => 'exact',
53
    'taskFor' => 'exact',
54
    'registeredBy' => 'exact',
55
    'taskStatus' => 'exact',
56
    'reason' => 'exact',
57
    'criticality' => 'exact',
58
    'category' => 'exact',
59
    'client' => 'exact',
60
    'order' => 'exact',
61
    'type' => 'exact'
62
])]
63
class Task
64
{
65
    #[ORM\Column(type: 'integer', nullable: false)]
66
    #[ORM\Id]
67
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
68
    #[Groups(['task:write', 'task:read', 'order:read'])]
69
    private $id;
70
71
    #[ORM\Column(name: 'name', type: 'string', length: 50, nullable: false)]
72
    #[Groups(['task:write', 'task:read', 'order:read'])]
73
    private $name;
74
75
    #[ORM\Column(name: 'task_type', type: 'string', length: 50, nullable: true)]
76
    #[Groups(['task:write', 'task:read', 'order:read'])]
77
    private $type;
78
79
    #[ORM\Column(name: 'due_date', type: 'datetime', nullable: true, columnDefinition: 'DATETIME')]
80
    #[Groups(['task:write', 'task:read', 'order:read'])]
81
    private $dueDate;
82
83
    #[ORM\ManyToOne(targetEntity: People::class)]
84
    #[ORM\JoinColumn(name: 'registered_by_id', referencedColumnName: 'id', nullable: false)]
85
    #[Groups(['task:write', 'task:read', 'order:read'])]
86
    private $registeredBy;
87
88
    #[ORM\ManyToOne(targetEntity: People::class)]
89
    #[ORM\JoinColumn(name: 'task_for_id', referencedColumnName: 'id', nullable: true)]
90
    #[Groups(['task:write', 'task:read', 'order:read'])]
91
    private $taskFor;
92
93
    #[ORM\ManyToOne(targetEntity: People::class)]
94
    #[ORM\JoinColumn(name: 'client_id', referencedColumnName: 'id', nullable: true)]
95
    #[Groups(['task:write', 'task:read', 'order:read'])]
96
    private $client;
97
98
    #[ORM\ManyToOne(targetEntity: Status::class)]
99
    #[ORM\JoinColumn(name: 'task_status_id', referencedColumnName: 'id', nullable: false)]
100
    #[Groups(['task:write', 'task:read', 'order:read'])]
101
    private $taskStatus;
102
103
    #[ORM\ManyToOne(targetEntity: Category::class)]
104
    #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id', nullable: true)]
105
    #[Groups(['task:write', 'task:read', 'order:read'])]
106
    private $category;
107
108
    #[ORM\ManyToOne(targetEntity: Category::class)]
109
    #[ORM\JoinColumn(name: 'reason_id', referencedColumnName: 'id', nullable: true)]
110
    #[Groups(['task:write', 'task:read', 'order:read'])]
111
    private $reason;
112
113
    #[ORM\ManyToOne(targetEntity: Category::class)]
114
    #[ORM\JoinColumn(name: 'criticality_id', referencedColumnName: 'id', nullable: true)]
115
    #[Groups(['task:write', 'task:read', 'order:read'])]
116
    private $criticality;
117
118
    #[ORM\ManyToOne(targetEntity: People::class)]
119
    #[ORM\JoinColumn(name: 'provider_id', referencedColumnName: 'id', nullable: false)]
120
    #[Groups(['task:write', 'task:read', 'order:read'])]
121
    private $provider;
122
123
    #[ORM\ManyToOne(targetEntity: Order::class, inversedBy: 'task')]
124
    #[ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id', nullable: true)]
125
    #[Groups(['task:read'])]
126
    private $order;
127
128
    #[ORM\Column(name: 'created_at', type: 'datetime', nullable: false, columnDefinition: 'DATETIME')]
129
    #[Groups(['task:write', 'task:read', 'order:read'])]
130
    private $createdAt;
131
132
    #[ORM\Column(name: 'alter_date', type: 'datetime', nullable: true, columnDefinition: 'DATETIME')]
133
    #[Groups(['task:write', 'task:read', 'order:read'])]
134
    private $alterDate;
135
136
    #[ORM\Column(name: 'announce', type: 'string', nullable: true)]
137
    #[Groups(['task:write', 'task:read', 'order:read'])]
138
    private string $announce;
139
140
    public function __construct()
141
    {
142
        $this->createdAt = new DateTime('now');
143
        $this->alterDate = new DateTime('now');
144
        $this->announce = json_encode(new stdClass());
145
    }
146
147
    public function getId()
148
    {
149
        return $this->id;
150
    }
151
152
    public function getName()
153
    {
154
        return $this->name;
155
    }
156
157
    public function setName($name): self
158
    {
159
        $this->name = $name;
160
        return $this;
161
    }
162
163
    public function getType()
164
    {
165
        return $this->type;
166
    }
167
168
    public function setType($type): self
169
    {
170
        $this->type = $type;
171
        return $this;
172
    }
173
174
    public function getDueDate()
175
    {
176
        return $this->dueDate;
177
    }
178
179
    public function setDueDate($dueDate): self
180
    {
181
        $this->dueDate = $dueDate;
182
        return $this;
183
    }
184
185
    public function getRegisteredBy()
186
    {
187
        return $this->registeredBy;
188
    }
189
190
    public function setRegisteredBy($registeredBy): self
191
    {
192
        $this->registeredBy = $registeredBy;
193
        return $this;
194
    }
195
196
    public function getTaskFor()
197
    {
198
        return $this->taskFor;
199
    }
200
201
    public function setTaskFor($taskFor): self
202
    {
203
        $this->taskFor = $taskFor;
204
        return $this;
205
    }
206
207
    public function getClient()
208
    {
209
        return $this->client;
210
    }
211
212
    public function setClient($client): self
213
    {
214
        $this->client = $client;
215
        return $this;
216
    }
217
218
    public function getTaskStatus()
219
    {
220
        return $this->taskStatus;
221
    }
222
223
    public function setTaskStatus($taskStatus): self
224
    {
225
        $this->taskStatus = $taskStatus;
226
        return $this;
227
    }
228
229
    public function getCategory()
230
    {
231
        return $this->category;
232
    }
233
234
    public function setCategory($category): self
235
    {
236
        $this->category = $category;
237
        return $this;
238
    }
239
240
    public function getReason()
241
    {
242
        return $this->reason;
243
    }
244
245
    public function setReason($reason): self
246
    {
247
        $this->reason = $reason;
248
        return $this;
249
    }
250
251
    public function getCriticality()
252
    {
253
        return $this->criticality;
254
    }
255
256
    public function setCriticality($criticality): self
257
    {
258
        $this->criticality = $criticality;
259
        return $this;
260
    }
261
262
    public function getProvider()
263
    {
264
        return $this->provider;
265
    }
266
267
    public function setProvider($provider): self
268
    {
269
        $this->provider = $provider;
270
        return $this;
271
    }
272
273
    public function getOrder()
274
    {
275
        return $this->order;
276
    }
277
278
    public function setOrder($order): self
279
    {
280
        $this->order = $order;
281
        return $this;
282
    }
283
284
    public function getCreatedAt()
285
    {
286
        return $this->createdAt;
287
    }
288
289
    public function getAlterDate()
290
    {
291
        return $this->alterDate;
292
    }
293
    public function getAnnounce(bool $decode = false): string|array
294
    {
295
        // Ensure we're decoding a string, even if it was temporarily an array internally
296
        $announceString = is_array($this->announce) ? json_encode($this->announce) : $this->announce;
0 ignored issues
show
introduced by
The condition is_array($this->announce) is always false.
Loading history...
297
        return $decode ? json_decode((string) $announceString, true) : (string) $announceString;
298
    }
299
300
    public function addAnnounce(mixed $value): self
301
    {
302
        $announce = $this->getAnnounce(true);
303
        
304
        if (!in_array($value, $announce))
0 ignored issues
show
Bug introduced by
It seems like $announce can also be of type string; however, parameter $haystack of in_array() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

304
        if (!in_array($value, /** @scrutinizer ignore-type */ $announce))
Loading history...
305
            array_push($announce, $value);
0 ignored issues
show
Bug introduced by
It seems like $announce can also be of type string; however, parameter $array of array_push() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

305
            array_push(/** @scrutinizer ignore-type */ $announce, $value);
Loading history...
306
307
        return $this->setAnnounce($announce);
308
    }
309
310
    public function setAnnounce(string|array|object $announce): self
311
    {
312
        if (is_string($announce))
0 ignored issues
show
introduced by
The condition is_string($announce) is always false.
Loading history...
313
            $announce = json_decode($announce, true);
314
315
        $this->announce = json_encode($announce);
316
        return $this;
317
    }
318
}
319