Skip to content

Commit

Permalink
fix: apply strict_types to main PHP files + fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed Apr 16, 2022
1 parent 0c42fbf commit 9f556cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions modules/VelonimoCard.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

class VelonimoCard
{
private int $bgaId;
Expand Down
10 changes: 9 additions & 1 deletion modules/VelonimoPlayer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

class VelonimoPlayer
{
private const ROUNDS_RANKING_SERIALIZED_KEY_VALUE_SEPARATOR = '=';
Expand Down Expand Up @@ -43,7 +45,13 @@ public static function deserializeRoundsRanking(string $serialized): array
{
/** @var string[] $rounds */
$rounds = explode(self::ROUNDS_RANKING_SERIALIZED_ROUNDS_SEPARATOR, $serialized);
if (!$rounds) {
if (
!$rounds
|| (
count($rounds) === 1
&& $rounds[0] === ''
)
) {
return [];
}

Expand Down
5 changes: 4 additions & 1 deletion modules/constants.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
/*

declare(strict_types=1);

/**
* Velonimo constants
*/

Expand Down
15 changes: 9 additions & 6 deletions velonimo.game.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/

declare(strict_types=1);

require_once(APP_GAMEMODULE_PATH.'module/table/table.game.php');
require_once('modules/constants.inc.php');
Expand Down Expand Up @@ -436,6 +437,8 @@ function stStartRound()
// if there is a loser, he plays first during this round
if ($currentLoser = $this->getCurrentLoser($players)) {
$this->gamestate->changeActivePlayer($currentLoser->getId());
} else {
self::activeNextPlayer();
}

$this->gamestate->nextState('firstPlayerTurn');
Expand Down Expand Up @@ -604,9 +607,9 @@ function upgradeTableDb($from_version)
private function fromBgaCardsToVelonimoCards(array $bgaCards): array {
return array_map(
fn (array $card) => new VelonimoCard(
$card['card_id'],
$card['card_type'],
$card['card_type_arg']
(int) $card['id'],
(int) $card['type'],
(int) $card['type_arg']
),
$bgaCards
);
Expand Down Expand Up @@ -656,11 +659,11 @@ private function getPlayersFromDatabase(): array {

return array_map(
fn (array $player) => new VelonimoPlayer(
$player['player_id'],
(int) $player['player_id'],
$player['player_name'],
$player['player_score'],
(int) $player['player_score'],
VelonimoPlayer::deserializeRoundsRanking($player['rounds_ranking']),
$player['is_wearing_jersey'],
((int) $player['is_wearing_jersey']) === 1,
),
$players
);
Expand Down

0 comments on commit 9f556cc

Please sign in to comment.