Passed
Push — develop ( 4d30ee...6a528e )
by BENARD
04:32
created

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