Skip to content

Commit

Permalink
Merge pull request #847 from PennyDreadfulMTG/infinite-life
Browse files Browse the repository at this point in the history
Revert "Bring standings props nullability into line with the database"
  • Loading branch information
bakert authored Nov 16, 2024
2 parents 19392c0 + dd28d2d commit 6eeffd1
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 58 deletions.
8 changes: 4 additions & 4 deletions gatherling/Models/Matchup.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function updateScores(string $structure): void
$playera_standing->score += 3;
} elseif ($structure == 'League' || $structure == 'League Match') {
$playera_standing->score += 3;
$playerb_standing->score += (int) $seasonRules['loss_pts'];
$playerb_standing->score += $seasonRules['loss_pts'];
}
$this->result = 'A';
} else {
Expand All @@ -398,7 +398,7 @@ public function updateScores(string $structure): void
$playerb_standing->score += 3;
} elseif ($structure == 'League' || $structure == 'League Match') {
$playerb_standing->score += 3;
$playera_standing->score += (int) $seasonRules['loss_pts'];
$playera_standing->score += $seasonRules['loss_pts'];
}
$this->result = 'B';
}
Expand Down Expand Up @@ -462,7 +462,7 @@ public function fixScores(string $structure): void
$playera_standing->score += 3;
$playera_standing->matches_won += 1;
if ($structure == 'League' || $structure == 'League Match') {
$playerb_standing->score += (int) $seasonRules['loss_pts'];
$playerb_standing->score += $seasonRules['loss_pts'];
}
if ($structure == 'Single Elimination') {
$playerb_standing->active = 0;
Expand All @@ -472,7 +472,7 @@ public function fixScores(string $structure): void
$playerb_standing->score += 3;
$playerb_standing->matches_won += 1;
if ($structure == 'League' || $structure == 'League Match') {
$playera_standing->score += (int) $seasonRules['loss_pts'];
$playera_standing->score += $seasonRules['loss_pts'];
}
if ($structure == 'Single Elimination') {
$playera_standing->active = 0;
Expand Down
70 changes: 34 additions & 36 deletions gatherling/Models/Standings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@

class Standings
{
public int $id;
public ?string $event = null; // belongs_to event
public ?string $player = null; // belongs_to player
public int $active;
public int $score;
public int $matches_played;
public int $matches_won;
public int $draws;
public int $games_won;
public int $games_played;
public int $byes;
public float $OP_Match;
public float $PL_Game;
public float $OP_Game;
public int $seed;
public int $matched;
public ?int $active = null;
public ?int $score;
public ?int $matches_played;
public ?int $matches_won;
public ?int $draws;
public ?int $games_won;
public ?int $games_played;
public ?int $byes;
public ?float $OP_Match;
public ?float $PL_Game;
public ?float $OP_Game;
public ?int $seed;
public ?int $matched;
public ?bool $new = null;

public function __construct(string $eventname, string $playername, int $initial_seed = 127)
{
// Check to see if we are doing event standings of player standings
if ($playername == '0') {
$this->id = 0;
$this->new = true;

return;
Expand All @@ -50,19 +52,9 @@ public function __construct(string $eventname, string $playername, int $initial_
$this->seed = $initial_seed;
return;
}
$this->active = $standings->active;
$this->matches_played = $standings->matches_played;
$this->games_won = $standings->games_won;
$this->games_played = $standings->games_played;
$this->byes = $standings->byes;
$this->OP_Match = $standings->OP_Match;
$this->PL_Game = $standings->PL_Game;
$this->OP_Game = $standings->OP_Game;
$this->score = $standings->score;
$this->seed = $standings->seed;
$this->matched = $standings->matched;
$this->matches_won = $standings->matches_won;
$this->draws = $standings->draws;
foreach (get_object_vars($standings) as $key => $value) {
$this->$key = $value;
}
}
}

Expand All @@ -87,10 +79,13 @@ public function save(): void
$this->draws = 0;

$sql = '
INSERT INTO standings (player, event, active, matches_played, draws, games_won, games_played,
matches_won, byes, OP_Match, PL_Game, OP_Game, score, seed, matched)
VALUES (:player, :event, :active, :matches_played, :draws, :games_won, :games_played,
:matches_won, :byes, :OP_Match, :PL_Game, :OP_Game, :score, :seed, :matched)';
INSERT INTO
standings
(player, event, active, matches_played, draws, games_won, games_played, matches_won, byes, OP_Match, PL_Game,
OP_Game, score, seed, matched)
VALUES
(:player, :event, :active, :matches_played, :draws, :games_won, :games_played, :matches_won, :byes, :OP_Match, :PL_Game,
:OP_Game, :score, :seed, :matched)';
$params = [
'player' => $this->player,
'event' => $this->event,
Expand All @@ -111,12 +106,15 @@ public function save(): void
db()->execute($sql, $params);
} else {
$sql = '
UPDATE standings
SET player = :player, event = :event, active = :active, matches_played = :matches_played,
games_won = :games_won, games_played = :games_played, byes = :byes, OP_Match = :OP_Match,
PL_Game = :PL_Game, OP_Game = :OP_Game, score = :score, seed = :seed, matched = :matched,
matches_won = :matches_won, draws = :draws
WHERE player = :player AND event = :event';
UPDATE
standings
SET
player = :player, event = :event, active = :active, matches_played = :matches_played,
games_won = :games_won, games_played = :games_played, byes = :byes, OP_Match = :OP_Match,
PL_Game = :PL_Game, OP_Game = :OP_Game, score = :score, seed = :seed, matched = :matched,
matches_won = :matches_won, draws = :draws
WHERE
player = :player AND event = :event';
$params = [
'player' => $this->player,
'event' => $this->event,
Expand Down
18 changes: 9 additions & 9 deletions gatherling/Models/StandingsDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

class StandingsDto extends Dto
{
public int $active;
public int $matches_played;
public int $games_won;
public int $games_played;
public int $byes;
public float $OP_Match;
public float $PL_Game;
public float $OP_Game;
public int $score;
public ?int $active;
public ?int $matches_played;
public ?int $games_won;
public ?int $games_played;
public ?int $byes;
public ?float $OP_Match;
public ?float $PL_Game;
public ?float $OP_Game;
public ?int $score;
public int $seed;
public int $matched;
public int $matches_won;
Expand Down
18 changes: 9 additions & 9 deletions gatherling/Views/Components/EventStandings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class EventStandings extends Component
rank: int,
gameName: GameName,
matchScore: int,
opMatch: string,
plGame: string,
opGame: string,
opMatch: ?string,
plGame: ?string,
opGame: ?string,
matchesPlayed: int,
byes: int,
}> */
Expand All @@ -37,12 +37,12 @@ public function __construct(
'shouldHighlight' => $standing->player == $playerName,
'rank' => $rank,
'gameName' => new GameName($sp, $event->client),
'matchScore' => $standing->score,
'opMatch' => number_format($standing->OP_Match, 3),
'plGame' => number_format($standing->PL_Game, 3),
'opGame' => number_format($standing->OP_Game, 3),
'matchesPlayed' => $standing->matches_played,
'byes' => $standing->byes,
'matchScore' => $standing->score ?? 0,
'opMatch' => $standing->OP_Match !== null ? number_format($standing->OP_Match, 3) : null,
'plGame' => $standing->PL_Game !== null ? number_format($standing->PL_Game, 3) : null,
'opGame' => $standing->OP_Game !== null ? number_format($standing->OP_Game, 3) : null,
'matchesPlayed' => $standing->matches_played ?? 0,
'byes' => $standing->byes ?? 0,
];
$rank++;
$standingInfoList[] = $standingInfo;
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ parameters:
count: 2
path: gatherling/Models/Formats.php

-
message: "#^Binary operation \"\\+\\=\" between int\\|null and int\\|string results in an error\\.$#"
count: 4
path: gatherling/Models/Matchup.php

-
message: "#^Parameter \\#1 \\$event_id of class Gatherling\\\\Models\\\\Entry constructor expects int, int\\|null given\\.$#"
count: 1
Expand Down
73 changes: 73 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,12 @@
<MixedAssignment>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<PossiblyInvalidOperand>
<code><![CDATA[$seasonRules['loss_pts']]]></code>
<code><![CDATA[$seasonRules['loss_pts']]]></code>
<code><![CDATA[$seasonRules['loss_pts']]]></code>
<code><![CDATA[$seasonRules['loss_pts']]]></code>
</PossiblyInvalidOperand>
<PossiblyNullArgument>
<code><![CDATA[$this->event_id]]></code>
<code><![CDATA[$this->eventname]]></code>
Expand All @@ -890,6 +896,43 @@
<code><![CDATA[$this->subevent]]></code>
<code><![CDATA[$this->subevent]]></code>
</PossiblyNullArgument>
<PossiblyNullOperand>
<code><![CDATA[$playera_standing->draws]]></code>
<code><![CDATA[$playera_standing->games_played]]></code>
<code><![CDATA[$playera_standing->games_played]]></code>
<code><![CDATA[$playera_standing->games_won]]></code>
<code><![CDATA[$playera_standing->games_won]]></code>
<code><![CDATA[$playera_standing->matches_played]]></code>
<code><![CDATA[$playera_standing->matches_played]]></code>
<code><![CDATA[$playera_standing->matches_won]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playera_standing->score]]></code>
<code><![CDATA[$playerb_standing->byes]]></code>
<code><![CDATA[$playerb_standing->byes]]></code>
<code><![CDATA[$playerb_standing->draws]]></code>
<code><![CDATA[$playerb_standing->games_played]]></code>
<code><![CDATA[$playerb_standing->games_played]]></code>
<code><![CDATA[$playerb_standing->games_won]]></code>
<code><![CDATA[$playerb_standing->games_won]]></code>
<code><![CDATA[$playerb_standing->matches_played]]></code>
<code><![CDATA[$playerb_standing->matches_played]]></code>
<code><![CDATA[$playerb_standing->matches_won]]></code>
<code><![CDATA[$playerb_standing->matches_won]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
<code><![CDATA[$playerb_standing->score]]></code>
</PossiblyNullOperand>
<PropertyNotSetInConstructor>
<code><![CDATA[$event_id]]></code>
<code><![CDATA[$eventname]]></code>
Expand Down Expand Up @@ -1448,7 +1491,37 @@
<code><![CDATA[$this->player]]></code>
<code><![CDATA[$this->player]]></code>
<code><![CDATA[$this->player]]></code>
<code><![CDATA[$value]]></code>
</MixedAssignment>
<PossiblyNullOperand>
<code><![CDATA[$opponent->draws]]></code>
<code><![CDATA[$opponent->draws]]></code>
<code><![CDATA[$opponent->games_played]]></code>
<code><![CDATA[$opponent->games_played]]></code>
<code><![CDATA[$opponent->games_won]]></code>
<code><![CDATA[$opponent->games_won]]></code>
<code><![CDATA[$opponent->matches_played]]></code>
<code><![CDATA[$opponent->matches_played]]></code>
<code><![CDATA[$opponent->matches_won]]></code>
<code><![CDATA[$opponent->matches_won]]></code>
<code><![CDATA[$this->games_played]]></code>
<code><![CDATA[$this->games_won]]></code>
</PossiblyNullOperand>
<PropertyNotSetInConstructor>
<code><![CDATA[$OP_Game]]></code>
<code><![CDATA[$OP_Match]]></code>
<code><![CDATA[$PL_Game]]></code>
<code><![CDATA[$byes]]></code>
<code><![CDATA[$draws]]></code>
<code><![CDATA[$games_played]]></code>
<code><![CDATA[$games_won]]></code>
<code><![CDATA[$id]]></code>
<code><![CDATA[$matched]]></code>
<code><![CDATA[$matches_played]]></code>
<code><![CDATA[$matches_won]]></code>
<code><![CDATA[$score]]></code>
<code><![CDATA[$seed]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="gatherling/Models/StandingsDto.php">
<MissingConstructor>
Expand Down

0 comments on commit 6eeffd1

Please sign in to comment.