Passed
Push — develop ( 8498a5...3a2333 )
by BENARD
04:18
created

Game   A

Complexity

Total Complexity 39

Size/Duplication

Total Lines 470
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 39
eloc 83
c 4
b 0
f 0
dl 0
loc 470
rs 9.28

37 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A getDefaultName() 0 3 1
A getId() 0 3 1
A setPicture() 0 5 1
A getPicture() 0 3 1
A setLibGameFr() 0 4 1
A getLibGameEn() 0 3 1
A setId() 0 4 1
A getLibGameFr() 0 3 1
A getName() 0 9 3
A setLibGameEn() 0 4 1
A getRules() 0 3 1
A removeRule() 0 3 1
A __construct() 0 6 1
A setBadge() 0 5 1
A getPublishedAt() 0 3 1
A getPlatforms() 0 3 1
A addGroup() 0 5 1
A getBoolRanking() 0 3 1
A getGroups() 0 3 1
A addRule() 0 4 1
A getStatus() 0 3 1
A setSerie() 0 5 1
A setBoolRanking() 0 5 1
A addPlatform() 0 4 1
A getBadge() 0 3 1
A getForum() 0 3 1
A getUrl() 0 6 1
A getSerie() 0 3 1
A setForum() 0 4 1
A getStatusAsString() 0 3 1
A setStatus() 0 5 1
A getPlaterGame() 0 3 1
A removeGroup() 0 3 1
A removePlatform() 0 3 1
A getSluggableFields() 0 3 1
A setPublishedAt() 0 5 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
     * @ORM\Column(name="status", type="string", length=30, nullable=false)
109
     */
110
    private string $status = GameStatus::STATUS_CREATED;
111
112
    /**
113
     * @ORM\Column(name="published_at", type="datetime", nullable=true)
114
     */
115
    private ?DateTime $publishedAt = null;
116
117
    /**
118
     * @ORM\Column(name="boolRanking", type="boolean", nullable=false, options={"default":1})
119
     */
120
    private bool $boolRanking = true;
121
122
    /**
123
     * @ORM\ManyToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Serie", inversedBy="games")
124
     * @ORM\JoinColumns({
125
     *   @ORM\JoinColumn(name="idSerie", referencedColumnName="id")
126
     * })
127
     */
128
    private ?Serie $serie;
129
130
    /**
131
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\Badge", inversedBy="game",cascade={"persist"}))
132
     * @ORM\JoinColumns({
133
     *   @ORM\JoinColumn(name="idBadge", referencedColumnName="id", nullable=true, onDelete="SET NULL")
134
     * })
135
     */
136
    private ?Badge $badge;
137
138
    /**
139
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\Group", mappedBy="game", cascade={"persist", "remove"}, orphanRemoval=true)
140
     */
141
    private Collection $groups;
142
143
    /**
144
     * @ORM\ManyToMany(targetEntity="Platform", inversedBy="games")
145
     * @ORM\JoinTable(name="vgr_game_platform",
146
     *      joinColumns={@ORM\JoinColumn(name="idGame", referencedColumnName="id")},
147
     *      inverseJoinColumns={@ORM\JoinColumn(name="idPlatform", referencedColumnName="id")}
148
     *      )
149
     * @ORM\OrderBy({"libPlatform" = "ASC"})
150
     */
151
    private Collection $platforms;
152
153
154
    /**
155
     * @ORM\OneToOne(targetEntity="VideoGamesRecords\CoreBundle\Entity\ForumInterface",cascade={"persist"})
156
     * @ORM\JoinColumn(name="idForum", referencedColumnName="id")
157
     */
158
    private $forum;
159
160
    /**
161
     * @ORM\ManyToMany(targetEntity="Rule", inversedBy="games")
162
     * @ORM\JoinTable(name="vgr_rule_game",
163
     *      joinColumns={@ORM\JoinColumn(name="idGame", referencedColumnName="id")},
164
     *      inverseJoinColumns={@ORM\JoinColumn(name="idRule", referencedColumnName="id")}
165
     *      )
166
     */
167
    private Collection $rules;
168
169
    /**
170
     * @ORM\OneToMany(targetEntity="VideoGamesRecords\CoreBundle\Entity\PlayerGame", mappedBy="game")
171
     */
172
    private $playerGame;
173
174
175
    /**
176
     * Constructor
177
     */
178
    public function __construct()
179
    {
180
        $this->groups = new ArrayCollection();
181
        $this->platforms = new ArrayCollection();
182
        $this->rules = new ArrayCollection();
183
        $this->playerGame = new ArrayCollection();
184
    }
185
186
    /**
187
     * @return string
188
     */
189
    public function __toString()
190
    {
191
        return sprintf('%s [%s]', $this->getDefaultName(), $this->id);
192
    }
193
194
    /**
195
     * @return string
196
     */
197
    public function getDefaultName(): string
198
    {
199
        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...
200
    }
201
202
    /**
203
     * @param string|null $locale
204
     * @return string|null
205
     */
206
    public function getName(string $locale = null): ?string
207
    {
208
        if ($locale === null) {
209
            $locale = Locale::getDefault();
210
        }
211
        if ($locale == 'fr') {
212
            return $this->libGameFr;
213
        } else {
214
            return $this->libGameEn;
215
        }
216
    }
217
218
    /**
219
     * Set id
220
     *
221
     * @param integer $id
222
     * @return Game
223
     */
224
    public function setId(int $id)
225
    {
226
        $this->id = $id;
227
        return $this;
228
    }
229
230
    /**
231
     * Get id
232
     *
233
     * @return integer
234
     */
235
    public function getId()
236
    {
237
        return $this->id;
238
    }
239
240
    /**
241
     * @param string $libGameEn
242
     * @return Game
243
     */
244
    public function setLibGameEn(string $libGameEn): Game
245
    {
246
        $this->libGameEn = $libGameEn;
247
        return $this;
248
    }
249
250
    /**
251
     * @return string|null
252
     */
253
    public function getLibGameEn(): ?string
254
    {
255
        return $this->libGameEn;
256
    }
257
258
    /**
259
     * @param string $libGameFr
260
     * @return Game
261
     */
262
    public function setLibGameFr(string $libGameFr): Game
263
    {
264
        $this->libGameFr = $libGameFr;
265
        return $this;
266
    }
267
268
    /**
269
     * @return string|null
270
     */
271
    public function getLibGameFr(): ?string
272
    {
273
        return $this->libGameFr;
274
    }
275
276
277
    /**
278
     * Set picture
279
     *
280
     * @param string|null $picture
281
     * @return Game
282
     */
283
    public function setPicture(string $picture = null): Game
284
    {
285
        $this->picture = $picture;
286
287
        return $this;
288
    }
289
290
    /**
291
     * Get picture
292
     * @return string|null
293
     */
294
    public function getPicture(): ?string
295
    {
296
        return $this->picture;
297
    }
298
299
    /**
300
     * Set status
301
     *
302
     * @param string $status
303
     * @return Game
304
     */
305
    public function setStatus(string $status): Game
306
    {
307
        $this->status = $status;
308
309
        return $this;
310
    }
311
312
    /**
313
     * Get status
314
     *
315
     * @return GameStatus
316
     */
317
    public function getStatus(): GameStatus
318
    {
319
        return new GameStatus($this->status);
320
    }
321
322
    /**
323
     * Get status
324
     *
325
     * @return string
326
     */
327
    public function getStatusAsString(): string
328
    {
329
        return $this->status;
330
    }
331
332
    /**
333
     * @param DateTime|null $pubishedAt
334
     * @return Game
335
     */
336
    public function setPublishedAt(DateTime $pubishedAt = null): Game
337
    {
338
        $this->publishedAt = $pubishedAt;
339
340
        return $this;
341
    }
342
343
    /**
344
     * Get publishedAt
345
     * @return DateTime|null
346
     */
347
    public function getPublishedAt(): ?DateTime
348
    {
349
        return $this->publishedAt;
350
    }
351
352
    /**
353
     * Set boolRanking
354
     *
355
     * @param bool $boolRanking
356
     * @return Game
357
     */
358
    public function setBoolRanking(bool $boolRanking): Game
359
    {
360
        $this->boolRanking = $boolRanking;
361
362
        return $this;
363
    }
364
365
    /**
366
     * Get boolRanking
367
     *
368
     * @return bool
369
     */
370
    public function getBoolRanking(): bool
371
    {
372
        return $this->boolRanking;
373
    }
374
375
376
    /**
377
     * Set Serie
378
     * @param Serie|null $serie
379
     * @return Game
380
     */
381
    public function setSerie(Serie $serie = null): Game
382
    {
383
        $this->serie = $serie;
384
385
        return $this;
386
    }
387
388
    /**
389
     * Get idSerie
390
     *
391
     * @return Serie
392
     */
393
    public function getSerie(): ?Serie
394
    {
395
        return $this->serie;
396
    }
397
398
    /**
399
     * Set badge
400
     *
401
     * @param $badge
402
     * @return Game
403
     */
404
    public function setBadge($badge = null): Game
405
    {
406
        $this->badge = $badge;
407
408
        return $this;
409
    }
410
411
    /**
412
     * Get idBadge
413
     * @return Badge|null
414
     */
415
    public function getBadge(): ?Badge
416
    {
417
        return $this->badge;
418
    }
419
420
    /**
421
     * @param Group $group
422
     * @return Game
423
     */
424
    public function addGroup(Group $group): Game
425
    {
426
        $group->setGame($this);
427
        $this->groups[] = $group;
428
        return $this;
429
    }
430
431
    /**
432
     * @param Group $group
433
     */
434
    public function removeGroup(Group $group)
435
    {
436
        $this->groups->removeElement($group);
437
    }
438
439
    /**
440
     * @return mixed
441
     */
442
    public function getGroups()
443
    {
444
        return $this->groups;
445
    }
446
447
    /**
448
     * @param Platform $platform
449
     * @return Game
450
     */
451
    public function addPlatform(Platform $platform): Game
452
    {
453
        $this->platforms[] = $platform;
454
        return $this;
455
    }
456
457
    /**
458
     * @param Platform $platform
459
     */
460
    public function removePlatform(Platform $platform)
461
    {
462
        $this->groups->removeElement($platform);
463
    }
464
465
    /**
466
     * @return mixed
467
     */
468
    public function getPlatforms()
469
    {
470
        return $this->platforms;
471
    }
472
473
474
    /**
475
     * @return ForumInterface
476
     */
477
    public function getForum()
478
    {
479
        return $this->forum;
480
    }
481
482
    /**
483
     * @param $forum
484
     * @return Game
485
     */
486
    public function setForum($forum): Game
487
    {
488
        $this->forum = $forum;
489
        return $this;
490
    }
491
492
    /**
493
     * Returns an array of the fields used to generate the slug.
494
     *
495
     * @return string[]
496
     */
497
    public function getSluggableFields(): array
498
    {
499
        return ['defaultName'];
500
    }
501
502
    /**
503
     * @return string
504
     */
505
    public function getUrl(): string
506
    {
507
        return sprintf(
508
            '%s-game-g%d/index',
509
            $this->getSlug(),
510
            $this->getId()
511
        );
512
    }
513
514
    /**
515
     * @param Rule $rule
516
     * @return Game
517
     */
518
    public function addRule(Rule $rule): Game
519
    {
520
        $this->rules[] = $rule;
521
        return $this;
522
    }
523
524
    /**
525
     * @param Rule $rule
526
     */
527
    public function removeRule(Rule $rule)
528
    {
529
        $this->rules->removeElement($rule);
530
    }
531
532
    public function getPlaterGame()
533
    {
534
        return $this->playerGame;
535
    }
536
537
    /**
538
     * @return mixed
539
     */
540
    public function getRules()
541
    {
542
        return $this->rules;
543
    }
544
}
545