Passed
Push — develop ( d64e19...d2a67e )
by BENARD
04:33
created

Game::getPicture()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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