| Total Complexity | 40 |
| Total Lines | 454 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 70 | #[ORM\Table(name:'vgr_player')] |
||
| 71 | #[ORM\Entity(repositoryClass: PlayerRepository::class)] |
||
| 72 | #[ORM\EntityListeners(["VideoGamesRecords\CoreBundle\EventListener\Entity\PlayerListener"])] |
||
| 73 | #[ORM\Index(name: "idx_point_game", columns: ["point_game"])] |
||
| 74 | #[ORM\Index(name: "idx_chart_rank", columns: ["chart_rank0", "chart_rank1", "chart_rank2", "chart_rank3"])] |
||
| 75 | #[ORM\Index(name: "idx_game_rank", columns: ["game_rank0", "game_rank1", "game_rank2", "game_rank3"])] |
||
| 76 | #[ApiResource( |
||
| 77 | order: ['pseudo' => 'ASC'], |
||
| 78 | operations: [ |
||
| 79 | new GetCollection(), |
||
| 80 | new GetCollection( |
||
| 81 | uriTemplate: '/players/autocomplete', |
||
| 82 | controller: Autocomplete::class, |
||
| 83 | normalizationContext: ['groups' => [ |
||
| 84 | 'player:read'] |
||
| 85 | ], |
||
| 86 | openapi: new Model\Operation( |
||
| 87 | summary: 'Retrieves players by autocompletion', |
||
| 88 | description: 'Retrieves players by autocompletion' |
||
| 89 | ), |
||
| 90 | openapiContext: [ |
||
| 91 | 'parameters' => [ |
||
| 92 | [ |
||
| 93 | 'name' => 'query', |
||
| 94 | 'in' => 'query', |
||
| 95 | 'type' => 'string', |
||
| 96 | 'required' => true |
||
| 97 | ] |
||
| 98 | ] |
||
| 99 | ] |
||
| 100 | ), |
||
| 101 | new GetCollection( |
||
| 102 | uriTemplate: '/players/ranking-point-chart', |
||
| 103 | controller: GetRankingPointChart::class, |
||
| 104 | ), |
||
| 105 | new GetCollection( |
||
| 106 | uriTemplate: '/players/ranking-point-game', |
||
| 107 | controller: GetRankingPointGame::class, |
||
| 108 | ), |
||
| 109 | new GetCollection( |
||
| 110 | uriTemplate: '/players/ranking-medal', |
||
| 111 | controller: GetRankingMedals::class, |
||
| 112 | ), |
||
| 113 | new GetCollection( |
||
| 114 | uriTemplate: '/players/ranking-cup', |
||
| 115 | controller: GetRankingCup::class, |
||
| 116 | ), |
||
| 117 | new GetCollection( |
||
| 118 | uriTemplate: '/players/ranking-badge', |
||
| 119 | controller: GetRankingBadge::class, |
||
| 120 | ), |
||
| 121 | new GetCollection( |
||
| 122 | uriTemplate: '/players/ranking-proof', |
||
| 123 | controller: GetRankingProof::class, |
||
| 124 | ), |
||
| 125 | new Get(), |
||
| 126 | new Get( |
||
| 127 | uriTemplate: '/players/{id}/nb-lost-position', |
||
| 128 | controller: GetNbLostPosition::class, |
||
| 129 | ), |
||
| 130 | new Get( |
||
| 131 | uriTemplate: '/players/{id}/nb-new-lost-position', |
||
| 132 | controller: GetNbNewLostPosition::class, |
||
| 133 | ), |
||
| 134 | new Get( |
||
| 135 | uriTemplate: '/players/{id}/can-ask-proof', |
||
| 136 | controller: CanAskProof::class, |
||
| 137 | ), |
||
| 138 | new Get( |
||
| 139 | uriTemplate: '/players/{id}/player-chart-stats', |
||
| 140 | controller: PlayerChartGetStats::class, |
||
| 141 | normalizationContext: ['groups' => [ |
||
| 142 | 'player-chart-status:read'] |
||
| 143 | ], |
||
| 144 | ), |
||
| 145 | new Get( |
||
| 146 | uriTemplate: '/players/{id}/game-stats', |
||
| 147 | controller: GameGetStats::class, |
||
| 148 | normalizationContext: ['groups' => [ |
||
| 149 | 'player-game:read', 'player-game:game', 'game:read', |
||
| 150 | 'game:platforms', 'platform:read', |
||
| 151 | 'player-game.statuses', 'player-chart-status:read'] |
||
| 152 | ], |
||
| 153 | ), |
||
| 154 | new Put( |
||
| 155 | denormalizationContext: ['groups' => ['player:update']], |
||
| 156 | security: 'is_granted("ROLE_PLAYER") and object.getUserId() == user.getId()' |
||
| 157 | ), |
||
| 158 | ], |
||
| 159 | normalizationContext: ['groups' => [ |
||
| 160 | 'player:read', |
||
| 161 | 'player:team', 'team:read', |
||
| 162 | 'player:country', 'country:read', |
||
| 163 | 'player:status', 'player-status:read'] |
||
| 164 | ], |
||
| 165 | )] |
||
| 166 | #[ApiResource( |
||
| 167 | uriTemplate: '/teams/{id}/players', |
||
| 168 | uriVariables: [ |
||
| 169 | 'id' => new Link(fromClass: Team::class, toProperty: 'team'), |
||
| 170 | ], |
||
| 171 | operations: [ new GetCollection() ], |
||
| 172 | normalizationContext: ['groups' => ['player:read']], |
||
| 173 | )] |
||
| 174 | #[ApiFilter( |
||
| 175 | SearchFilter::class, |
||
| 176 | properties: [ |
||
| 177 | 'pseudo' => 'partial', |
||
| 178 | 'user.enabled' => 'exact', |
||
| 179 | ] |
||
| 180 | )] |
||
| 181 | #[ApiFilter( |
||
| 182 | OrderFilter::class, |
||
| 183 | properties: [ |
||
| 184 | 'id' => 'ASC', |
||
| 185 | 'pseudo' => 'ASC', |
||
| 186 | 'createdAt' => 'ASC', |
||
| 187 | 'nbConnexion' => 'DESC', |
||
| 188 | 'lastLogin' => 'DESC', |
||
| 189 | 'nbForumMessage' => 'DESC', |
||
| 190 | 'nbChart' => 'DESC', |
||
| 191 | 'nbVideo' => 'DESC', |
||
| 192 | ] |
||
| 193 | )] |
||
| 194 | #[ApiFilter( |
||
| 195 | GroupFilter::class, |
||
| 196 | arguments: [ |
||
| 197 | 'parameterName' => 'groups', |
||
| 198 | 'overrideDefaultGroups' => true, |
||
| 199 | 'whitelist' => [ |
||
| 200 | 'player:read', |
||
| 201 | 'player:team', |
||
| 202 | 'player:country', |
||
| 203 | 'country:read', |
||
| 204 | 'player:read', |
||
| 205 | 'player:team', |
||
| 206 | 'team:read', |
||
| 207 | 'player:status', |
||
| 208 | 'player-status:read', |
||
| 209 | ] |
||
| 210 | ] |
||
| 211 | )] |
||
| 212 | #[ApiFilter(DateFilter::class, properties: ['lastLogin' => DateFilterInterface::EXCLUDE_NULL])] |
||
| 213 | #[ApiFilter(RangeFilter::class, properties: ['nbVideo'])] |
||
| 214 | #[ApiFilter(BooleanFilter::class, properties: ['hasDonate'])] |
||
| 215 | class Player implements SluggableInterface |
||
| 216 | { |
||
| 217 | use TimestampableEntity; |
||
| 218 | use SluggableTrait; |
||
| 219 | use RankCupTrait; |
||
| 220 | use GameRank0Trait; |
||
| 221 | use GameRank1Trait; |
||
| 222 | use GameRank2Trait; |
||
| 223 | use GameRank3Trait; |
||
| 224 | use RankMedalTrait; |
||
| 225 | use ChartRank0Trait; |
||
| 226 | use ChartRank1Trait; |
||
| 227 | use ChartRank2Trait; |
||
| 228 | use ChartRank3Trait; |
||
| 229 | use ChartRank4Trait; |
||
| 230 | use ChartRank5Trait; |
||
| 231 | use RankPointBadgeTrait; |
||
| 232 | use PointBadgeTrait; |
||
| 233 | use RankPointChartTrait; |
||
| 234 | use PointChartTrait; |
||
| 235 | use RankPointGameTrait; |
||
| 236 | use PointGameTrait; |
||
| 237 | use AverageChartRankTrait; |
||
| 238 | use AverageGameRankTrait; |
||
| 239 | use PlayerCommunicationDataTrait; |
||
| 240 | use PlayerPersonalDataTrait; |
||
| 241 | use NbChartTrait; |
||
| 242 | use NbChartProvenTrait; |
||
| 243 | use NbGameTrait; |
||
| 244 | use NbVideoTrait; |
||
| 245 | use NbMasterBadgeTrait; |
||
| 246 | |||
| 247 | #[ORM\Column(nullable: false)] |
||
| 248 | private int $user_id; |
||
| 249 | |||
| 250 | #[ApiProperty(identifier: true)] |
||
| 251 | #[ORM\Id, ORM\Column, ORM\GeneratedValue] |
||
| 252 | private ?int $id = null; |
||
| 253 | |||
| 254 | #[Assert\Length(min: 3, max: 50)] |
||
| 255 | #[ORM\Column(length: 50, nullable: false, unique: true)] |
||
| 256 | private string $pseudo; |
||
| 257 | |||
| 258 | #[Assert\Length(max: 100)] |
||
| 259 | #[ORM\Column(length: 100, nullable: false, options: ['default' => "default.jpg"])] |
||
| 260 | private string $avatar = 'default.jpg'; |
||
| 261 | |||
| 262 | #[Assert\Length(max: 50)] |
||
| 263 | #[ORM\Column(length: 50, nullable: true)] |
||
| 264 | private ?string $gamerCard = null; |
||
| 265 | |||
| 266 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 267 | private int $rankProof = 0; |
||
| 268 | |||
| 269 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 270 | private int $rankCountry = 0; |
||
| 271 | |||
| 272 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 273 | private int $nbChartMax = 0; |
||
| 274 | |||
| 275 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 276 | private int $nbChartWithPlatform = 0; |
||
| 277 | |||
| 278 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 279 | private int $nbChartDisabled = 0; |
||
| 280 | |||
| 281 | #[ORM\Column(nullable: true)] |
||
| 282 | protected ?DateTime $lastLogin = null; |
||
| 283 | |||
| 284 | #[ORM\Column(nullable: false, options: ['default' => 0])] |
||
| 285 | protected int $nbConnexion = 0; |
||
| 286 | |||
| 287 | #[ORM\Column(nullable: false, options: ['default' => false])] |
||
| 288 | private bool $boolMaj = false; |
||
| 289 | |||
| 290 | #[ORM\Column(nullable: false, options: ['default' => false])] |
||
| 291 | private bool $hasDonate = false; |
||
| 292 | |||
| 293 | #[ORM\ManyToOne(targetEntity: Team::class, inversedBy: 'players')] |
||
| 294 | #[ORM\JoinColumn(name:'team_id', referencedColumnName:'id', nullable:true, onDelete: 'SET NULL')] |
||
| 295 | private ?Team $team; |
||
| 296 | |||
| 297 | #[ORM\Column(nullable: true)] |
||
| 298 | protected ?DateTime $lastDisplayLostPosition; |
||
| 299 | |||
| 300 | #[ORM\ManyToOne(targetEntity: PlayerStatus::class)] |
||
| 301 | #[ORM\JoinColumn(name:'status_id', referencedColumnName:'id', nullable:false)] |
||
| 302 | private PlayerStatus $status; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @var Collection<int, Proof> |
||
| 306 | */ |
||
| 307 | #[ORM\OneToMany(targetEntity: Proof::class, mappedBy: 'playerResponding')] |
||
| 308 | private Collection $proofRespondings; |
||
|
|
|||
| 309 | |||
| 310 | /** |
||
| 311 | * @var Collection<int, PlayerGame> |
||
| 312 | */ |
||
| 313 | #[ORM\OneToMany(targetEntity: PlayerGame::class, mappedBy: 'player')] |
||
| 314 | private Collection $playerGame; |
||
| 315 | |||
| 316 | |||
| 317 | public function __toString() |
||
| 318 | { |
||
| 319 | return sprintf('%s (%d)', $this->getPseudo(), $this->getId()); |
||
| 320 | } |
||
| 321 | |||
| 322 | public function setId(int $id): void |
||
| 323 | { |
||
| 324 | $this->id = $id; |
||
| 325 | } |
||
| 326 | |||
| 327 | public function getId(): ?int |
||
| 328 | { |
||
| 329 | return $this->id; |
||
| 330 | } |
||
| 331 | |||
| 332 | public function setPseudo(string $pseudo): void |
||
| 333 | { |
||
| 334 | $this->pseudo = $pseudo; |
||
| 335 | } |
||
| 336 | |||
| 337 | public function getPseudo(): string |
||
| 338 | { |
||
| 339 | return $this->pseudo; |
||
| 340 | } |
||
| 341 | |||
| 342 | public function setAvatar(string $avatar): void |
||
| 343 | { |
||
| 344 | $this->avatar = $avatar; |
||
| 345 | } |
||
| 346 | |||
| 347 | public function getAvatar(): string |
||
| 348 | { |
||
| 349 | return $this->avatar; |
||
| 350 | } |
||
| 351 | |||
| 352 | public function setGamerCard(string $gamerCard): void |
||
| 353 | { |
||
| 354 | $this->gamerCard = $gamerCard; |
||
| 355 | } |
||
| 356 | |||
| 357 | public function getGamerCard(): ?string |
||
| 358 | { |
||
| 359 | return $this->gamerCard; |
||
| 360 | } |
||
| 361 | |||
| 362 | |||
| 363 | public function setRankProof(int $rankProof): void |
||
| 364 | { |
||
| 365 | $this->rankProof = $rankProof; |
||
| 366 | } |
||
| 367 | |||
| 368 | public function getRankProof(): ?int |
||
| 369 | { |
||
| 370 | return $this->rankProof; |
||
| 371 | } |
||
| 372 | |||
| 373 | public function setRankCountry(int $rankCountry): void |
||
| 374 | { |
||
| 375 | $this->rankCountry = $rankCountry; |
||
| 376 | } |
||
| 377 | |||
| 378 | public function getRankCountry(): ?int |
||
| 379 | { |
||
| 380 | return $this->rankCountry; |
||
| 381 | } |
||
| 382 | |||
| 383 | public function setNbChartMax(int $nbChartMax): void |
||
| 384 | { |
||
| 385 | $this->nbChartMax = $nbChartMax; |
||
| 386 | } |
||
| 387 | |||
| 388 | public function getNbChartMax(): int |
||
| 389 | { |
||
| 390 | return $this->nbChartMax; |
||
| 391 | } |
||
| 392 | |||
| 393 | public function setNbChartWithPlatform(int $nbChartWithPlatform): void |
||
| 394 | { |
||
| 395 | $this->nbChartWithPlatform = $nbChartWithPlatform; |
||
| 396 | } |
||
| 397 | |||
| 398 | public function getNbChartWithPlatform(): int |
||
| 399 | { |
||
| 400 | return $this->nbChartWithPlatform; |
||
| 401 | } |
||
| 402 | |||
| 403 | public function setNbChartDisabled(int $nbChartDisabled): void |
||
| 404 | { |
||
| 405 | $this->nbChartDisabled = $nbChartDisabled; |
||
| 406 | } |
||
| 407 | |||
| 408 | public function getNbChartDisabled(): int |
||
| 409 | { |
||
| 410 | return $this->nbChartDisabled; |
||
| 411 | } |
||
| 412 | |||
| 413 | public function getLastLogin(): ?DateTime |
||
| 414 | { |
||
| 415 | return $this->lastLogin; |
||
| 416 | } |
||
| 417 | |||
| 418 | public function setLastLogin(DateTime $time = null): void |
||
| 419 | { |
||
| 420 | $this->lastLogin = $time; |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @return int |
||
| 425 | */ |
||
| 426 | public function getUserId(): int |
||
| 427 | { |
||
| 428 | return $this->user_id; |
||
| 429 | } |
||
| 430 | |||
| 431 | public function setUserId($userId): Player |
||
| 432 | { |
||
| 433 | $this->user_id = $userId; |
||
| 434 | return $this; |
||
| 435 | } |
||
| 436 | |||
| 437 | public function setTeam(Team $team = null): void |
||
| 438 | { |
||
| 439 | $this->team = $team; |
||
| 440 | } |
||
| 441 | |||
| 442 | public function getTeam(): ?Team |
||
| 443 | { |
||
| 444 | return $this->team; |
||
| 445 | } |
||
| 446 | |||
| 447 | public function getLastDisplayLostPosition(): ?DateTime |
||
| 448 | { |
||
| 449 | return $this->lastDisplayLostPosition; |
||
| 450 | } |
||
| 451 | |||
| 452 | |||
| 453 | public function setLastDisplayLostPosition(DateTime $lastDisplayLostPosition = null): void |
||
| 454 | { |
||
| 455 | $this->lastDisplayLostPosition = $lastDisplayLostPosition; |
||
| 456 | } |
||
| 457 | |||
| 458 | public function setBoolMaj(bool $boolMaj): void |
||
| 459 | { |
||
| 460 | $this->boolMaj = $boolMaj; |
||
| 461 | } |
||
| 462 | |||
| 463 | public function getBoolMaj(): bool |
||
| 464 | { |
||
| 465 | return $this->boolMaj; |
||
| 466 | } |
||
| 467 | |||
| 468 | public function getHasDonate(): bool |
||
| 469 | { |
||
| 470 | return $this->hasDonate; |
||
| 471 | } |
||
| 472 | |||
| 473 | public function setHasDonate(bool $hasDonate): void |
||
| 474 | { |
||
| 475 | $this->hasDonate = $hasDonate; |
||
| 476 | } |
||
| 477 | |||
| 478 | public function setStatus(PlayerStatus $status): void |
||
| 479 | { |
||
| 480 | $this->status = $status; |
||
| 481 | } |
||
| 482 | |||
| 483 | public function getStatus(): PlayerStatus |
||
| 484 | { |
||
| 485 | return $this->status; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @return int |
||
| 490 | */ |
||
| 491 | public function getNbConnexion(): int |
||
| 492 | { |
||
| 493 | return $this->nbConnexion; |
||
| 494 | } |
||
| 495 | |||
| 496 | public function setNbConnexion(int $nbConnexion): void |
||
| 499 | } |
||
| 500 | |||
| 501 | |||
| 502 | public function getSluggableFields(): array |
||
| 503 | { |
||
| 504 | return ['pseudo']; |
||
| 505 | } |
||
| 506 | |||
| 507 | public function getInitial(): string |
||
| 508 | { |
||
| 509 | return substr($this->pseudo, 0, 1); |
||
| 510 | } |
||
| 511 | |||
| 512 | |||
| 513 | public function isLeader(): bool |
||
| 514 | { |
||
| 515 | return ($this->getTeam() !== null) && ($this->getTeam()->getLeader()->getId() === $this->getId()); |
||
| 516 | } |
||
| 517 | |||
| 518 | public function getUrl(): string |
||
| 519 | { |
||
| 520 | return sprintf( |
||
| 521 | '%s-player-p%d/index', |
||
| 522 | $this->getSlug(), |
||
| 523 | $this->getId() |
||
| 524 | ); |
||
| 525 | } |
||
| 526 | } |
||
| 527 |