Passed
Push — develop ( ee6f8b...860277 )
by BENARD
04:16
created

Game::setDownloadUrl()   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 VideoGamesRecords\CoreBundle\Entity;
4
5
use ApiPlatform\Core\Annotation\ApiFilter;
6
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
7
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
8
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
9
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
10
use DateTime;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use Knp\DoctrineBehaviors\Contract\Entity\SluggableInterface;
15
use Knp\DoctrineBehaviors\Model\Sluggable\SluggableTrait;
16
use Gedmo\Timestampable\Traits\TimestampableEntity;
17
use Symfony\Component\Intl\Locale;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Intl\Locale 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 Symfony\Component\Validator\Constraints as Assert;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraints 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 VideoGamesRecords\CoreBundle\Model\Entity\NbChartTrait;
20
use VideoGamesRecords\CoreBundle\Model\Entity\NbPlayerTrait;
21
use VideoGamesRecords\CoreBundle\Model\Entity\NbPostTrait;
22
use VideoGamesRecords\CoreBundle\Model\Entity\NbTeamTrait;
23
use VideoGamesRecords\CoreBundle\ValueObject\GameStatus;
24
25
/**
26
 * Game
27
 *
28
 * @ORM\Table(
29
 *     name="vgr_game",
30
 *     indexes={
31
 *         @ORM\Index(name="idx_libGameFr", columns={"libGameFr"}),
32
 *         @ORM\Index(name="idx_libGameEn", columns={"libGameEn"}),
33
 *         @ORM\Index(name="idx_status", columns={"status"})
34
 *     }
35
 * )
36
 * @ORM\Entity(repositoryClass="VideoGamesRecords\CoreBundle\Repository\GameRepository")
37
 * @ORM\EntityListeners({"VideoGamesRecords\CoreBundle\EventListener\Entity\GameListener"})
38
 * @ApiFilter(
39
 *     SearchFilter::class,
40
 *     properties={
41
 *          "status": "exact",
42
 *          "platforms": "exact",
43
 *          "playerGame.player": "exact",
44
 *          "groups.charts.lostPositions.player": "exact",
45
 *          "libGameEn" : "partial",
46
 *          "libGameFr" : "partial",
47
 *          "badge": "exact",
48
 *      }
49
 * )
50
 * @ApiFilter(DateFilter::class, properties={"publishedAt": DateFilter::INCLUDE_NULL_BEFORE_AND_AFTER})
51
 * @ApiFilter(
52
 *     GroupFilter::class,
53
 *     arguments={
54
 *          "parameterName": "groups",
55
 *          "overrideDefaultGroups": true,
56
 *          "whitelist": {"game.read.mini","game.list","game.platforms","platform.read"}
57
 *     }
58
 * )
59
 * @ApiFilter(
60
 *     OrderFilter::class,
61
 *     properties={
62
 *          "id":"ASC",
63
 *          "libGameEn" : "ASC",
64
 *          "libGameFr" : "ASC",
65
 *          "publishedAt": "DESC",
66
 *          "nbChart": "DESC",
67
 *          "nbPost": "DESC",
68
 *          "nbPlayer": "DESC"
69
 *     },
70
 *     arguments={"orderParameterName"="order"}
71
 * )
72
 */
73
class Game implements SluggableInterface
74
{
75
    use TimestampableEntity;
76
    use SluggableTrait;
77
    use NbChartTrait;
78
    use NbPostTrait;
79
    use NbPlayerTrait;
80
    use NbTeamTrait;
81
82
    /**
83
     * @ORM\Column(name="id", type="integer")
84
     * @ORM\Id
85
     * @ORM\GeneratedValue(strategy="IDENTITY")
86
     */
87
    protected ?int $id = null;
88
89
    /**
90
     * @Assert\Length(max="255")
91
     * @ORM\Column(name="libGameEn", type="string", length=255, nullable=false)
92
     */
93
    private ?string $libGameEn;
94
95
    /**
96
     * @Assert\Length(max="255")
97
     * @ORM\Column(name="libGameFr", type="string", length=255, nullable=false)
98
     */
99
    private ?string $libGameFr = null;
100
101
    /**
102
     * @Assert\Length(max="200")
103
     * @ORM\Column(name="picture", type="string", length=200, nullable=true)
104
     */
105
    private ?string $picture;
106
107
    /**
108
     * @Assert\Length(max="255")
109
     * @ORM\Column(name="downloadUrl", type="string", length=255, nullable=true)
110
     */
111
    private ?string $downloadUrl;
0 ignored issues
show
introduced by
The private property $downloadUrl is not used, and could be removed.
Loading history...
112
113
    /**
114
     * @ORM\Column(name="status", type="string", length=30, nullable=false)
115
     */
116
    private string $status = GameStatus::STATUS_CREATED;
117
118
    /**
119
     * @ORM\Column(name="published_at", type="datetime", nullable=true)
120
     */
121
    private ?DateTime $publishedAt = null;
122
123
    /**
124
     * @ORM\Column(name="boolRanking", type="boolean", nullable=false, options={"default":1})
125
     */
126
    private bool $boolRanking = true;
127
128
    /**
129
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Serie", inversedBy="games")
130
     * @ORM\JoinColumns({
131
     *   @ORM\JoinColumn(name="idSerie", referencedColumnName="id")
132
     * })
133
     */
134
    private ?Serie $serie;
135
136
    /**
137
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Badge", inversedBy="game",cascade={"persist"}))
138
     * @ORM\JoinColumns({
139
     *   @ORM\JoinColumn(name="idBadge", referencedColumnName="id", nullable=true, onDelete="SET NULL")
140
     * })
141
     */
142
    private ?Badge $badge;
143
144
    /**
145
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Group", mappedBy="game", cascade={"persist", "remove"}, orphanRemoval=true)
146
     */
147
    private Collection $groups;
148
149
    /**
150
     * @ORM\ManyToMany(targetEntity="Platform", inversedBy="games")
151
     * @ORM\JoinTable(name="vgr_game_platform",
152
     *      joinColumns={@ORM\JoinColumn(name="idGame", referencedColumnName="id")},
153
     *      inverseJoinColumns={@ORM\JoinColumn(name="idPlatform", referencedColumnName="id")}
154
     *      )
155
     * @ORM\OrderBy({"libPlatform" = "ASC"})
156
     */
157
    private Collection $platforms;
158
159
160
    /**
161
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\ForumInterface",cascade={"persist"})
162
     * @ORM\JoinColumn(name="idForum", referencedColumnName="id")
163
     */
164
    private $forum;
165
166
    /**
167
     * @ORM\ManyToMany(targetEntity="Rule", inversedBy="games")
168
     * @ORM\JoinTable(name="vgr_rule_game",
169
     *      joinColumns={@ORM\JoinColumn(name="idGame", referencedColumnName="id")},
170
     *      inverseJoinColumns={@ORM\JoinColumn(name="idRule", referencedColumnName="id")}
171
     *      )
172
     */
173
    private Collection $rules;
174
175
    /**
176
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerGame", mappedBy="game")
177
     */
178
    private $playerGame;
0 ignored issues
show
introduced by
The private property $playerGame is not used, and could be removed.
Loading history...
179
180
181
    /**
182
     * Constructor
183
     */
184
    public function __construct()
185
    {
186
        $this->groups = new ArrayCollection();
187
        $this->platforms = new ArrayCollection();
188
        $this->rules = new ArrayCollection();
189
    }
190
191
    /**
192
     * @return string
193
     */
194
    public function __toString()
195
    {
196
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    public function getDefaultName(): string
203
    {
204
        return $this->libGameEn;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->libGameEn could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
205
    }
206
207
    /**
208
     * @param string|null $locale
209
     * @return string|null
210
     */
211
    public function getName(string $locale = null): ?string
212
    {
213
        if ($locale === null) {
214
            $locale = Locale::getDefault();
215
        }
216
        if ($locale == 'fr') {
217
            return $this->libGameFr;
218
        } else {
219
            return $this->libGameEn;
220
        }
221
    }
222
223
    /**
224
     * Set id
225
     *
226
     * @param integer $id
227
     * @return Game
228
     */
229
    public function setId(int $id)
230
    {
231
        $this->id = $id;
232
        return $this;
233
    }
234
235
    /**
236
     * Get id
237
     *
238
     * @return integer
239
     */
240
    public function getId()
241
    {
242
        return $this->id;
243
    }
244
245
    /**
246
     * @param string $libGameEn
247
     * @return Game
248
     */
249
    public function setLibGameEn(string $libGameEn): Game
250
    {
251
        $this->libGameEn = $libGameEn;
252
        return $this;
253
    }
254
255
    /**
256
     * @return string|null
257
     */
258
    public function getLibGameEn(): ?string
259
    {
260
        return $this->libGameEn;
261
    }
262
263
    /**
264
     * @param string $libGameFr
265
     * @return Game
266
     */
267
    public function setLibGameFr(string $libGameFr): Game
268
    {
269
        $this->libGameFr = $libGameFr;
270
        return $this;
271
    }
272
273
    /**
274
     * @return string|null
275
     */
276
    public function getLibGameFr(): ?string
277
    {
278
        return $this->libGameFr;
279
    }
280
281
282
    /**
283
     * Set picture
284
     *
285
     * @param string|null $picture
286
     * @return Game
287
     */
288
    public function setPicture(string $picture = null): Game
289
    {
290
        $this->picture = $picture;
291
292
        return $this;
293
    }
294
295
    /**
296
     * Get picture
297
     * @return string|null
298
     */
299
    public function getPicture(): ?string
300
    {
301
        return $this->picture;
302
    }
303
304
    /**
305
     * Set status
306
     *
307
     * @param string $status
308
     * @return Game
309
     */
310
    public function setStatus(string $status): Game
311
    {
312
        $this->status = $status;
313
314
        return $this;
315
    }
316
317
    /**
318
     * Get status
319
     *
320
     * @return GameStatus
321
     */
322
    public function getStatus(): GameStatus
323
    {
324
        return new GameStatus($this->status);
325
    }
326
327
    /**
328
     * Get status
329
     *
330
     * @return string
331
     */
332
    public function getStatusAsString(): string
333
    {
334
        return $this->status;
335
    }
336
337
    /**
338
     * @param DateTime|null $pubishedAt
339
     * @return Game
340
     */
341
    public function setPublishedAt(DateTime $pubishedAt = null): Game
342
    {
343
        $this->publishedAt = $pubishedAt;
344
345
        return $this;
346
    }
347
348
    /**
349
     * Get publishedAt
350
     * @return DateTime|null
351
     */
352
    public function getPublishedAt(): ?DateTime
353
    {
354
        return $this->publishedAt;
355
    }
356
357
    /**
358
     * Set boolRanking
359
     *
360
     * @param bool $boolRanking
361
     * @return Game
362
     */
363
    public function setBoolRanking(bool $boolRanking): Game
364
    {
365
        $this->boolRanking = $boolRanking;
366
367
        return $this;
368
    }
369
370
    /**
371
     * Get boolRanking
372
     *
373
     * @return bool
374
     */
375
    public function getBoolRanking(): bool
376
    {
377
        return $this->boolRanking;
378
    }
379
380
381
    /**
382
     * Set Serie
383
     * @param Serie|null $serie
384
     * @return Game
385
     */
386
    public function setSerie(Serie $serie = null): Game
387
    {
388
        $this->serie = $serie;
389
390
        return $this;
391
    }
392
393
    /**
394
     * Get idSerie
395
     *
396
     * @return Serie
397
     */
398
    public function getSerie(): ?Serie
399
    {
400
        return $this->serie;
401
    }
402
403
    /**
404
     * Set badge
405
     *
406
     * @param $badge
407
     * @return Game
408
     */
409
    public function setBadge($badge = null): Game
410
    {
411
        $this->badge = $badge;
412
413
        return $this;
414
    }
415
416
    /**
417
     * Get idBadge
418
     * @return Badge|null
419
     */
420
    public function getBadge(): ?Badge
421
    {
422
        return $this->badge;
423
    }
424
425
    /**
426
     * @param Group $group
427
     * @return Game
428
     */
429
    public function addGroup(Group $group): Game
430
    {
431
        $group->setGame($this);
432
        $this->groups[] = $group;
433
        return $this;
434
    }
435
436
    /**
437
     * @param Group $group
438
     */
439
    public function removeGroup(Group $group)
440
    {
441
        $this->groups->removeElement($group);
442
    }
443
444
    /**
445
     * @return mixed
446
     */
447
    public function getGroups()
448
    {
449
        return $this->groups;
450
    }
451
452
    /**
453
     * @param Platform $platform
454
     * @return Game
455
     */
456
    public function addPlatform(Platform $platform): Game
457
    {
458
        $this->platforms[] = $platform;
459
        return $this;
460
    }
461
462
    /**
463
     * @param Platform $platform
464
     */
465
    public function removePlatform(Platform $platform)
466
    {
467
        $this->groups->removeElement($platform);
468
    }
469
470
    /**
471
     * @return mixed
472
     */
473
    public function getPlatforms()
474
    {
475
        return $this->platforms;
476
    }
477
478
479
    /**
480
     * @return ForumInterface
481
     */
482
    public function getForum()
483
    {
484
        return $this->forum;
485
    }
486
487
    /**
488
     * @param $forum
489
     * @return Game
490
     */
491
    public function setForum($forum): Game
492
    {
493
        $this->forum = $forum;
494
        return $this;
495
    }
496
497
    /**
498
     * Returns an array of the fields used to generate the slug.
499
     *
500
     * @return string[]
501
     */
502
    public function getSluggableFields(): array
503
    {
504
        return ['defaultName'];
505
    }
506
507
    /**
508
     * @return string
509
     */
510
    public function getUrl(): string
511
    {
512
        return sprintf(
513
            '%s-game-g%d/index',
514
            $this->getSlug(),
515
            $this->getId()
516
        );
517
    }
518
519
    /**
520
     * @param Rule $rule
521
     * @return Game
522
     */
523
    public function addRule(Rule $rule): Game
524
    {
525
        $this->rules[] = $rule;
526
        return $this;
527
    }
528
529
    /**
530
     * @param Rule $rule
531
     */
532
    public function removeRule(Rule $rule)
533
    {
534
        $this->rules->removeElement($rule);
535
    }
536
537
    /**
538
     * @return mixed
539
     */
540
    public function getRules()
541
    {
542
        return $this->rules;
543
    }
544
}
545