Skip to content

Commit

Permalink
Make getTeamsSortedByScore() more resilient
Browse files Browse the repository at this point in the history
Fix a bug that would occur when trying to access a team that had played
in a match in a tournament, but is no longer part of that tournament.
  • Loading branch information
Fabian-Sommer committed Mar 7, 2022
1 parent 062dce1 commit c416e3f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/rikki/heroeslounge/models/Division.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,17 @@ public function getTeamsSortedByScore()
}
foreach ($this->matches as $match) {
if ($match->winner) {
$teams->where('id', $match->winner->id)->first()->score += 3;
$winningTeam = $teams->where('id', $match->winner->id)->first();
if ($winningTeam) {
$winningTeam->score += 3;
}
} elseif ($match->is_played) {
//tie
foreach($match->teams as $team) {
$teams->where('id', $team->id)->first()->score++;
$t = $teams->where('id', $team->id)->first();
if ($t) {
$t->score += 1;
}
}
}

Expand Down

0 comments on commit c416e3f

Please sign in to comment.