Player   B
last analyzed

Complexity

Total Complexity 47

Size/Duplication

Total Lines 594
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 1
Metric Value
eloc 271
dl 0
loc 594
rs 8.64
c 6
b 0
f 1
wmc 47

45 Methods

Rating   Name   Duplication   Size   Complexity  
A setNbConnexion() 0 3 1
A setNbChartWithPlatform() 0 3 1
A setStatus() 0 3 1
A getLastDisplayLostPosition() 0 3 1
A getPlayerCharts() 0 3 1
A setId() 0 3 1
A getUserId() 0 3 1
A getSluggableFields() 0 3 1
A getAvatar() 0 3 1
A getId() 0 3 1
A setPseudo() 0 3 1
A getHasDonate() 0 3 1
A setNbChartDisabled() 0 3 1
A setGamerCard() 0 3 1
A getUrl() 0 6 1
A getNbConnexion() 0 3 1
A getGamerCard() 0 3 1
A getTeam() 0 3 1
A setTeam() 0 3 1
A getSlug() 0 3 1
A isLeader() 0 3 2
A getFriends() 0 3 1
A addFriend() 0 7 2
A getRankCountry() 0 3 1
A getLastLogin() 0 3 1
A setRankProof() 0 3 1
A getNbChartMax() 0 3 1
A setBoolMaj() 0 3 1
A __construct() 0 5 1
A setLastDisplayLostPosition() 0 3 1
A getNbChartDisabled() 0 3 1
A setLastLogin() 0 3 1
A getNbChartWithPlatform() 0 3 1
A setUserId() 0 4 1
A getInitial() 0 3 1
A setHasDonate() 0 3 1
A getBoolMaj() 0 3 1
A setNbChartMax() 0 3 1
A getPseudo() 0 3 1
A setRankCountry() 0 3 1
A getRankProof() 0 3 1
A setAvatar() 0 3 1
A removeFriend() 0 5 1
A getStatus() 0 3 1
A __toString() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like Player often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Player, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Entity;
6
7
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
8
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
9
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
10
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
11
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;
12
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
13
use ApiPlatform\Metadata\ApiFilter;
14
use ApiPlatform\Metadata\ApiProperty;
15
use ApiPlatform\Metadata\ApiResource;
16
use ApiPlatform\Metadata\Get;
17
use ApiPlatform\Metadata\GetCollection;
18
use ApiPlatform\Metadata\Link;
19
use ApiPlatform\Metadata\Post;
20
use ApiPlatform\Metadata\Put;
21
use ApiPlatform\OpenApi\Model;
22
use DateTime;
23
use Doctrine\Common\Collections\ArrayCollection;
24
use Doctrine\Common\Collections\Collection;
25
use Doctrine\ORM\Mapping as ORM;
26
use Gedmo\Mapping\Annotation as Gedmo;
27
use Gedmo\Timestampable\Traits\TimestampableEntity;
28
use Symfony\Component\Validator\Constraints as Assert;
29
use VideoGamesRecords\CoreBundle\Controller\Player\Autocomplete;
30
use VideoGamesRecords\CoreBundle\Controller\Player\Friend\AddFriend;
31
use VideoGamesRecords\CoreBundle\Controller\Player\Friend\GetFriends;
32
use VideoGamesRecords\CoreBundle\Controller\Player\Game\GetStats as GameGetStats;
33
use VideoGamesRecords\CoreBundle\Controller\Player\GetBadges;
34
use VideoGamesRecords\CoreBundle\Controller\Player\GetGamesFromLostPositions;
35
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingBadge;
36
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingCup;
37
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingMedals;
38
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingPointChart;
39
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingPointGame;
40
use VideoGamesRecords\CoreBundle\Controller\Player\GetRankingProof;
41
use VideoGamesRecords\CoreBundle\Controller\Player\LostPosition\GetNbLostPosition;
42
use VideoGamesRecords\CoreBundle\Controller\Player\OrderMasterBadges;
43
use VideoGamesRecords\CoreBundle\Controller\Player\LostPosition\GetNbNewLostPosition;
44
use VideoGamesRecords\CoreBundle\Controller\Player\PlayerChart\GetStats as PlayerChartGetStats;
45
use VideoGamesRecords\CoreBundle\Controller\Player\ProofRequest\CanAskProof;
46
use VideoGamesRecords\CoreBundle\Filter\PlayerSearchFilter;
47
use VideoGamesRecords\CoreBundle\Repository\PlayerRepository;
48
use VideoGamesRecords\CoreBundle\Traits\Entity\AverageChartRankTrait;
49
use VideoGamesRecords\CoreBundle\Traits\Entity\AverageGameRankTrait;
50
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank0Trait;
51
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank1Trait;
52
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank2Trait;
53
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank3Trait;
54
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank4Trait;
55
use VideoGamesRecords\CoreBundle\Traits\Entity\ChartRank5Trait;
56
use VideoGamesRecords\CoreBundle\Traits\Entity\GameRank0Trait;
57
use VideoGamesRecords\CoreBundle\Traits\Entity\GameRank1Trait;
58
use VideoGamesRecords\CoreBundle\Traits\Entity\GameRank2Trait;
59
use VideoGamesRecords\CoreBundle\Traits\Entity\GameRank3Trait;
60
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartProvenTrait;
61
use VideoGamesRecords\CoreBundle\Traits\Entity\NbChartTrait;
62
use VideoGamesRecords\CoreBundle\Traits\Entity\NbGameTrait;
63
use VideoGamesRecords\CoreBundle\Traits\Entity\NbMasterBadgeTrait;
64
use VideoGamesRecords\CoreBundle\Traits\Entity\NbVideoTrait;
65
use VideoGamesRecords\CoreBundle\Traits\Entity\Player\PlayerCommunicationDataTrait;
66
use VideoGamesRecords\CoreBundle\Traits\Entity\Player\PlayerPersonalDataTrait;
67
use VideoGamesRecords\CoreBundle\Traits\Entity\PointBadgeTrait;
68
use VideoGamesRecords\CoreBundle\Traits\Entity\PointChartTrait;
69
use VideoGamesRecords\CoreBundle\Traits\Entity\PointGameTrait;
70
use VideoGamesRecords\CoreBundle\Traits\Entity\RankCupTrait;
71
use VideoGamesRecords\CoreBundle\Traits\Entity\RankMedalTrait;
72
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointBadgeTrait;
73
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointChartTrait;
74
use VideoGamesRecords\CoreBundle\Traits\Entity\RankPointGameTrait;
75
76
#[ORM\Table(name:'vgr_player')]
77
#[ORM\Entity(repositoryClass: PlayerRepository::class)]
78
#[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\PlayerListener"])]
79
#[ORM\Index(name: "idx_point_game", columns: ["point_game"])]
80
#[ORM\Index(name: "idx_chart_rank", columns: ["chart_rank0", "chart_rank1", "chart_rank2", "chart_rank3"])]
81
#[ORM\Index(name: "idx_game_rank", columns: ["game_rank0", "game_rank1", "game_rank2", "game_rank3"])]
82
#[ApiResource(
83
    operations: [
84
        new GetCollection(),
85
        new GetCollection(
86
            uriTemplate: '/players/autocomplete',
87
            controller: Autocomplete::class,
88
            normalizationContext: ['groups' => [
89
                'player:read:minimal']
90
            ],
91
            openapi: new Model\Operation(
92
                summary: 'Retrieves players by autocompletion',
93
                description: 'Retrieves players by autocompletion'
94
            ),
95
            /*openapiContext: [
96
            'parameters' => [
97
            [
98
            'name' => 'query',
99
            'in' => 'query',
100
            'type' => 'string',
101
            'required' => true
102
            ]
103
            ]
104
            ]*/
105
        ),
106
        new GetCollection(
107
            uriTemplate: '/players/ranking-point-chart',
108
            controller: GetRankingPointChart::class,
109
        ),
110
        new GetCollection(
111
            uriTemplate: '/players/ranking-point-game',
112
            controller: GetRankingPointGame::class,
113
        ),
114
        new GetCollection(
115
            uriTemplate: '/players/ranking-medal',
116
            controller: GetRankingMedals::class,
117
        ),
118
        new GetCollection(
119
            uriTemplate: '/players/ranking-cup',
120
            controller: GetRankingCup::class,
121
        ),
122
        new GetCollection(
123
            uriTemplate: '/players/ranking-badge',
124
            controller: GetRankingBadge::class,
125
        ),
126
        new GetCollection(
127
            uriTemplate: '/players/ranking-proof',
128
            controller: GetRankingProof::class,
129
        ),
130
        new Get(),
131
        new Get(
132
            uriTemplate: '/players/{id}/get-nb-lost-position',
133
            controller: GetNbLostPosition::class,
134
        ),
135
        new Get(
136
            uriTemplate: '/players/{id}/get-nb-new-lost-position',
137
            controller: GetNbNewLostPosition::class,
138
        ),
139
        new Get(
140
            uriTemplate: '/players/{id}/can-ask-proof',
141
            controller: CanAskProof::class,
142
        ),
143
        new Get(
144
            uriTemplate: '/players/{id}/player-chart-stats',
145
            controller: PlayerChartGetStats::class,
146
            normalizationContext: ['groups' => [
147
                'player-chart-status:read']
148
            ],
149
        ),
150
        new Get(
151
            uriTemplate: '/players/{id}/game-stats',
152
            controller: GameGetStats::class,
153
            normalizationContext: ['groups' => [
154
                'player-game:read', 'player-game:game', 'game:read',
155
                'game:platforms', 'platform:read',
156
                'player-game.statuses', 'player-chart-status:read']
157
            ],
158
        ),
159
        new Get(
160
            uriTemplate: '/players/{id}/games-from-lost-positions',
161
            controller: GetGamesFromLostPositions::class,
162
            normalizationContext: ['groups' => [
163
                'game:read:minimal']
164
            ],
165
        ),
166
        new GetCollection(
167
            uriTemplate: '/players/{id}/badges',
168
            controller: GetBadges::class,
169
            normalizationContext: ['groups' => [
170
                'player-badge:read', 'player-badge:badge', 'badge:read',
171
                'badge:serie', 'serie:read',
172
                'badge:game', 'game:read',
173
                'badge:platform', 'platform:read',
174
            ]
175
            ]
176
        ),
177
        new GetCollection(
178
            uriTemplate: '/players/{id}/friends',
179
            controller: GetFriends::class,
180
            normalizationContext: ['groups' => ['player:read:minimal']]
181
        ),
182
        new Post(
183
            uriTemplate: '/players/add-friend',
184
            status: 200,
185
            controller: AddFriend::class,
186
            /*openapi: new Model\Operation(
187
                responses: [
188
                    '200' => [
189
                        'description' => 'Friend added successfully',
190
                        'content' => [
191
                            'application/json' => [
192
                                'schema' => [
193
                                    'type' => 'object',
194
                                    'properties' => [
195
                                        'success' => [
196
                                            'type' => 'boolean',
197
                                            'example' => true
198
                                        ]
199
                                    ]
200
                                ]
201
                            ]
202
                        ]
203
                    ],
204
                    '400' => [
205
                        'description' => 'Bad request - friend_id is required'
206
                    ],
207
                    '404' => [
208
                        'description' => 'Friend not found'
209
                    ]
210
                ],
211
                summary: 'Add a friend to the current player',
212
                description: 'Add a friend to the current player by providing friend_id in request body',
213
                requestBody: new Model\RequestBody(
214
                    content: new \ArrayObject([
215
                        'application/json' => [
216
                            'schema' => [
217
                                'type' => 'object',
218
                                'properties' => [
219
                                    'friend_id' => [
220
                                        'type' => 'integer',
221
                                        'example' => 0
222
                                    ]
223
                                ],
224
                                'required' => ['friend_id']
225
                            ]
226
                        ]
227
                    ])
228
                )
229
            ),*/
230
            security: 'is_granted("ROLE_USER")',
231
            validate: false
232
        ),
233
        new Post(
234
            uriTemplate: '/players/{id}/order-master-badges',
235
            controller: OrderMasterBadges::class,
236
            security: 'object.getUserId() == user.getId()',
237
            openapi: new Model\Operation(
238
                summary: 'Order master badges for a player',
239
                requestBody: new Model\RequestBody(
240
                    content: new \ArrayObject([
241
                        'application/json' => [
242
                            'schema' => [
243
                                'type' => 'array',
244
                                'items' => [
245
                                    'type' => 'object',
246
                                    'properties' => [
247
                                        'id' => ['type' => 'integer'],
248
                                        'mbOrder' => ['type' => 'integer']
249
                                    ],
250
                                    'required' => ['id', 'mbOrder']
251
                                ]
252
                            ]
253
                        ]
254
                    ])
255
                )
256
            )
257
        ),
258
        new Put(
259
            denormalizationContext: ['groups' => ['player:update']],
260
            security: 'is_granted("ROLE_PLAYER") and object.getUserId() == user.getId()'
261
        ),
262
    ],
263
    normalizationContext: ['groups' => [
264
        'player:read',
265
        'player:team', 'team:read:minimal',
266
        'player:country', 'country:read',
267
        'player:status', 'player-status:read']
268
    ],
269
    order: ['pseudo' => 'ASC'],
270
)]
271
#[ApiResource(
272
    uriTemplate: '/teams/{id}/players',
273
    uriVariables: [
274
        'id' => new Link(fromClass: Team::class, toProperty: 'team'),
275
    ],
276
    operations: [ new GetCollection() ],
277
    normalizationContext: ['groups' => ['player:read:minimal']],
278
)]
279
#[ApiFilter(
280
    SearchFilter::class,
281
    properties: [
282
        'pseudo' => 'partial',
283
        'user.enabled' => 'exact',
284
    ]
285
)]
286
#[ApiFilter(
287
    OrderFilter::class,
288
    properties: [
289
        'id' => 'ASC',
290
        'pseudo' => 'ASC',
291
        'createdAt' => 'ASC',
292
        'nbConnexion' => 'DESC',
293
        'lastLogin' => 'DESC',
294
        'nbForumMessage' => 'DESC',
295
        'nbChart' => 'DESC',
296
        'nbVideo' => 'DESC',
297
        'nbGame' => 'DESC',
298
        'pointGame' => 'DESC',
299
    ]
300
)]
301
#[ApiFilter(DateFilter::class, properties: ['lastLogin' => DateFilterInterface::EXCLUDE_NULL])]
302
#[ApiFilter(RangeFilter::class, properties: ['nbVideo'])]
303
#[ApiFilter(BooleanFilter::class, properties: ['hasDonate'])]
304
#[ApiFilter(PlayerSearchFilter::class)]
305
class Player
306
{
307
    use TimestampableEntity;
308
    use RankCupTrait;
309
    use GameRank0Trait;
310
    use GameRank1Trait;
311
    use GameRank2Trait;
312
    use GameRank3Trait;
313
    use RankMedalTrait;
314
    use ChartRank0Trait;
315
    use ChartRank1Trait;
316
    use ChartRank2Trait;
317
    use ChartRank3Trait;
318
    use ChartRank4Trait;
319
    use ChartRank5Trait;
320
    use RankPointBadgeTrait;
321
    use PointBadgeTrait;
322
    use RankPointChartTrait;
323
    use PointChartTrait;
324
    use RankPointGameTrait;
325
    use PointGameTrait;
326
    use AverageChartRankTrait;
327
    use AverageGameRankTrait;
328
    use PlayerCommunicationDataTrait;
329
    use PlayerPersonalDataTrait;
330
    use NbChartTrait;
331
    use NbChartProvenTrait;
332
    use NbGameTrait;
333
    use NbVideoTrait;
334
    use NbMasterBadgeTrait;
335
336
    #[ORM\Column(nullable: false)]
337
    private int $user_id;
338
339
    #[ApiProperty(identifier: true)]
340
    #[ORM\Id, ORM\Column, ORM\GeneratedValue]
341
    private ?int $id = null;
342
343
    #[Assert\Length(min: 3, max: 50)]
344
    #[ORM\Column(length: 50, nullable: false, unique: true)]
345
    private string $pseudo;
346
347
    #[Assert\Length(max: 100)]
348
    #[ORM\Column(length: 100, nullable: false, options: ['default' => "default.jpg"])]
349
    private string $avatar = 'default.jpg';
350
351
    #[Assert\Length(max: 50)]
352
    #[ORM\Column(length: 50, nullable: true)]
353
    private ?string $gamerCard = null;
354
355
    #[ORM\Column(nullable: false, options: ['default' => 0])]
356
    private int $rankProof = 0;
357
358
    #[ORM\Column(nullable: false, options: ['default' => 0])]
359
    private int $rankCountry = 0;
360
361
    #[ORM\Column(nullable: false, options: ['default' => 0])]
362
    private int $nbChartMax = 0;
363
364
    #[ORM\Column(nullable: false, options: ['default' => 0])]
365
    private int $nbChartWithPlatform = 0;
366
367
    #[ORM\Column(nullable: false, options: ['default' => 0])]
368
    private int $nbChartDisabled = 0;
369
370
    #[ORM\Column(nullable: true)]
371
    protected ?DateTime $lastLogin = null;
372
373
    #[ORM\Column(nullable: false, options: ['default' => 0])]
374
    protected int $nbConnexion = 0;
375
376
    #[ORM\Column(nullable: false, options: ['default' => false])]
377
    private bool $boolMaj = false;
378
379
    #[ORM\Column(nullable: false, options: ['default' => false])]
380
    private bool $hasDonate = false;
381
382
    #[ORM\ManyToOne(targetEntity: Team::class, inversedBy: 'players')]
383
    #[ORM\JoinColumn(name:'team_id', referencedColumnName:'id', nullable:true, onDelete: 'SET NULL')]
384
    private ?Team $team;
385
386
    #[ORM\Column(nullable: true)]
387
    protected ?DateTime $lastDisplayLostPosition;
388
389
    #[ORM\ManyToOne(targetEntity: PlayerStatus::class)]
390
    #[ORM\JoinColumn(name:'status_id', referencedColumnName:'id', nullable:false)]
391
    private PlayerStatus $status;
392
393
    #[ORM\Column(length: 128)]
394
    #[Gedmo\Slug(fields: ['pseudo'])]
395
    protected string $slug;
396
397
398
    /**
399
     * @var Collection<int, Proof>
400
     */
401
    #[ORM\OneToMany(targetEntity: Proof::class, mappedBy: 'playerResponding')]
402
    private Collection $proofRespondings;
0 ignored issues
show
introduced by
The private property $proofRespondings is not used, and could be removed.
Loading history...
403
404
    /**
405
     * @var Collection<int, PlayerGame>
406
     */
407
    #[ORM\OneToMany(targetEntity: PlayerGame::class, mappedBy: 'player')]
408
    private Collection $playerGame;
409
410
    /**
411
     * @var Collection<int, PlayerChart>
412
     */
413
    #[ORM\OneToMany(targetEntity: PlayerChart::class, mappedBy: 'player')]
414
    private Collection $playerCharts;
415
416
    /**
417
     * @var Collection<int, Player>
418
     */
419
    #[ORM\ManyToMany(targetEntity: Player::class)]
420
    #[ORM\JoinTable(name: 'vgr_friend')]
421
    #[ORM\JoinColumn(name: 'player_id', referencedColumnName: 'id')]
422
    #[ORM\InverseJoinColumn(name: 'friend_id', referencedColumnName: 'id')]
423
    private Collection $friends;
424
425
    public function __construct()
426
    {
427
        $this->playerGame = new ArrayCollection();
428
        $this->playerCharts = new ArrayCollection();
429
        $this->friends = new ArrayCollection();
430
    }
431
432
    public function __toString()
433
    {
434
        return sprintf('%s (%d)', $this->getPseudo(), $this->getId());
435
    }
436
437
    public function setId(int $id): void
438
    {
439
        $this->id = $id;
440
    }
441
442
    public function getId(): ?int
443
    {
444
        return $this->id;
445
    }
446
447
    public function setPseudo(string $pseudo): void
448
    {
449
        $this->pseudo = $pseudo;
450
    }
451
452
    public function getPseudo(): string
453
    {
454
        return $this->pseudo;
455
    }
456
457
    public function setAvatar(string $avatar): void
458
    {
459
        $this->avatar = $avatar;
460
    }
461
462
    public function getAvatar(): string
463
    {
464
        return $this->avatar;
465
    }
466
467
    public function setGamerCard(string $gamerCard): void
468
    {
469
        $this->gamerCard = $gamerCard;
470
    }
471
472
    public function getGamerCard(): ?string
473
    {
474
        return $this->gamerCard;
475
    }
476
477
478
    public function setRankProof(int $rankProof): void
479
    {
480
        $this->rankProof = $rankProof;
481
    }
482
483
    public function getRankProof(): ?int
484
    {
485
        return $this->rankProof;
486
    }
487
488
    public function setRankCountry(int $rankCountry): void
489
    {
490
        $this->rankCountry = $rankCountry;
491
    }
492
493
    public function getRankCountry(): ?int
494
    {
495
        return $this->rankCountry;
496
    }
497
498
    public function setNbChartMax(int $nbChartMax): void
499
    {
500
        $this->nbChartMax = $nbChartMax;
501
    }
502
503
    public function getNbChartMax(): int
504
    {
505
        return $this->nbChartMax;
506
    }
507
508
    public function setNbChartWithPlatform(int $nbChartWithPlatform): void
509
    {
510
        $this->nbChartWithPlatform = $nbChartWithPlatform;
511
    }
512
513
    public function getNbChartWithPlatform(): int
514
    {
515
        return $this->nbChartWithPlatform;
516
    }
517
518
    public function setNbChartDisabled(int $nbChartDisabled): void
519
    {
520
        $this->nbChartDisabled = $nbChartDisabled;
521
    }
522
523
    public function getNbChartDisabled(): int
524
    {
525
        return $this->nbChartDisabled;
526
    }
527
528
    public function getLastLogin(): ?DateTime
529
    {
530
        return $this->lastLogin;
531
    }
532
533
    public function setLastLogin(?DateTime $time = null): void
534
    {
535
        $this->lastLogin = $time;
536
    }
537
538
    /**
539
     * @return int
540
     */
541
    public function getUserId(): int
542
    {
543
        return $this->user_id;
544
    }
545
546
    public function setUserId($userId): Player
547
    {
548
        $this->user_id = $userId;
549
        return $this;
550
    }
551
552
    public function setTeam(?Team $team = null): void
553
    {
554
        $this->team = $team;
555
    }
556
557
    public function getTeam(): ?Team
558
    {
559
        return $this->team;
560
    }
561
562
    public function getLastDisplayLostPosition(): ?DateTime
563
    {
564
        return $this->lastDisplayLostPosition;
565
    }
566
567
568
    public function setLastDisplayLostPosition(?DateTime $lastDisplayLostPosition = null): void
569
    {
570
        $this->lastDisplayLostPosition = $lastDisplayLostPosition;
571
    }
572
573
    public function setBoolMaj(bool $boolMaj): void
574
    {
575
        $this->boolMaj = $boolMaj;
576
    }
577
578
    public function getBoolMaj(): bool
579
    {
580
        return $this->boolMaj;
581
    }
582
583
    public function getHasDonate(): bool
584
    {
585
        return $this->hasDonate;
586
    }
587
588
    public function setHasDonate(bool $hasDonate): void
589
    {
590
        $this->hasDonate = $hasDonate;
591
    }
592
593
    public function setStatus(PlayerStatus $status): void
594
    {
595
        $this->status = $status;
596
    }
597
598
    public function getStatus(): PlayerStatus
599
    {
600
        return $this->status;
601
    }
602
603
    public function getSlug(): string
604
    {
605
        return $this->slug;
606
    }
607
608
    /**
609
     * @return int
610
     */
611
    public function getNbConnexion(): int
612
    {
613
        return $this->nbConnexion;
614
    }
615
616
    public function setNbConnexion(int $nbConnexion): void
617
    {
618
        $this->nbConnexion = $nbConnexion;
619
    }
620
621
622
    public function getSluggableFields(): array
623
    {
624
        return ['pseudo'];
625
    }
626
627
    public function getInitial(): string
628
    {
629
        return substr($this->pseudo, 0, 1);
630
    }
631
632
633
    public function isLeader(): bool
634
    {
635
        return ($this->getTeam() !== null) && ($this->getTeam()->getLeader()->getId() === $this->getId());
636
    }
637
638
    public function getPlayerCharts(): Collection
639
    {
640
        return $this->playerCharts;
641
    }
642
643
    public function getFriends(): Collection
644
    {
645
        return $this->friends;
646
    }
647
648
    public function addFriend(Player $friend): self
649
    {
650
        if (!$this->friends->contains($friend)) {
651
            $this->friends->add($friend);
652
        }
653
654
        return $this;
655
    }
656
657
    public function removeFriend(Player $friend): self
658
    {
659
        $this->friends->removeElement($friend);
660
661
        return $this;
662
    }
663
664
    public function getUrl(): string
665
    {
666
        return sprintf(
667
            '%s-player-p%d/index',
668
            $this->getSlug(),
669
            $this->getId()
670
        );
671
    }
672
}
673