Skip to content

Commit

Permalink
fixed phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Aug 6, 2024
1 parent e1c0eb2 commit fa0b1e3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use kissj\Participant\Patrol\PatrolParticipant;
use kissj\Participant\Patrol\PatrolsRoster;
use kissj\Participant\Patrol\SinglePatrolRoster;
use kissj\Participant\Troop\TroopParticipant;
use kissj\User\User;
use kissj\User\UserRole;
use kissj\User\UserStatus;
Expand Down Expand Up @@ -204,9 +205,23 @@ private function filterEmptyParticipants(array $participants): array
* @param Participant[] $participants
* @return Participant[]
*/
private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array{
usort($participants,
function ($a, $b) { return ($a->troopLeader ?? $a->patrolLeader ?? $a->id) - ($b->troopLeader ?? $b->patrolLeader ?? $b->id); });
private function sortParticipantsBasedOnTroopOrPatrol(array $participants): array
{
usort(
$participants,
function (Participant $a, Participant $b) {
if ($a instanceof PatrolParticipant && $b instanceof PatrolParticipant) {
return $a->patrolLeader->id <=> $b->patrolLeader->id;
}

if ($a instanceof TroopParticipant && $b instanceof TroopParticipant) {
return ($a->troopLeader->id ?? $a->id) <=> ($b->troopLeader->id ?? $a->id);
}

return $a->id <=> $b->id;
},
);

return $participants;
}

Expand Down

0 comments on commit fa0b1e3

Please sign in to comment.