Passed
Push — develop ( 574080...0f5d99 )
by BENARD
04:30
created

Game::setLibGameEn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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