diff --git a/composer.json b/composer.json index df7f68d2a..c1f44b42e 100644 --- a/composer.json +++ b/composer.json @@ -81,10 +81,10 @@ "require-dev": { "fig-r/psr2r-sniffer": "2.1.1", "overtrue/phplint": "9.5.5", - "phpstan/phpstan": "1.12.5", + "phpstan/phpstan": "2.0.3", "phpunit/phpunit": "11.5.0", "phpunit/php-code-coverage": "11.0.8", - "rector/rector": "0.15.13", + "rector/rector": "2.0.0", "squizlabs/php_codesniffer": "3.11.2" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f9158adc5..f3928146c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,9 +10,6 @@ parameters: # Stricter analysis polluteScopeWithLoopInitialAssignments: false polluteScopeWithAlwaysIterableForeach: false - checkAlwaysTrueCheckTypeFunctionCall: true - checkAlwaysTrueInstanceof: true - checkAlwaysTrueStrictComparison: true checkExplicitMixedMissingReturn: true checkFunctionNameCase: true checkInternalClassCaseSensitivity: true diff --git a/src/lib/Default/alliance_pick.inc.php b/src/lib/Default/alliance_pick.inc.php index df873d27a..6e8ddeec3 100644 --- a/src/lib/Default/alliance_pick.inc.php +++ b/src/lib/Default/alliance_pick.inc.php @@ -36,6 +36,10 @@ function get_draft_teams(int $gameId): array { } } + if (count($teams) === 0) { + throw new Exception('No draft leaders have been selected yet.'); + } + // Determine the smallest team alliance size. $minSize = min(array_map(fn(array $i): int => $i['Size'], $teams)); diff --git a/src/lib/Smr/AbstractPlayer.php b/src/lib/Smr/AbstractPlayer.php index 5b2f0071e..3461a77f1 100644 --- a/src/lib/Smr/AbstractPlayer.php +++ b/src/lib/Smr/AbstractPlayer.php @@ -2051,6 +2051,9 @@ public function getBounties(): array { return $this->bounties; } + /** + * @phpstan-assert-if-false array{} $this->getBounties() + */ public function hasBounties(): bool { return count($this->getBounties()) > 0; } diff --git a/src/lib/Smr/Chess/Board.php b/src/lib/Smr/Chess/Board.php index 3dce2eea2..20ac0681f 100644 --- a/src/lib/Smr/Chess/Board.php +++ b/src/lib/Smr/Chess/Board.php @@ -11,7 +11,7 @@ class Board { /** @var array, array> */ private array $canCastle; - /** @var array{X: int, Y: int}> */ + /** @var array{X: int, Y: int} */ private array $enPassantPawn; /** @var array> */ private array $board; @@ -190,7 +190,7 @@ public function canCastle(Colour $colour, Castling $type): bool { } /** - * @return array{'X': int, 'Y': int} + * @return array{X: int, Y: int} */ public function getEnPassantPawn(): array { return $this->enPassantPawn; diff --git a/src/lib/Smr/Chess/ChessPiece.php b/src/lib/Smr/Chess/ChessPiece.php index 5358762ad..30865c5ba 100644 --- a/src/lib/Smr/Chess/ChessPiece.php +++ b/src/lib/Smr/Chess/ChessPiece.php @@ -43,7 +43,7 @@ public function isAttacking(Board $board, int $x, int $y): bool { } /** - * @return array> + * @return array */ public function getPossibleMoves(Board $board, bool $attackingCheck = false): array { $moves = []; @@ -139,7 +139,7 @@ public function getPossibleMoves(Board $board, bool $attackingCheck = false): ar } /** - * @param array{int, int} $moves + * @param list $moves */ private function addMove(int $toX, int $toY, Board $board, array &$moves, bool $attackingCheck = true): bool { if ($board->isValidCoord($toX, $toY)) { diff --git a/src/lib/Smr/Globals.php b/src/lib/Smr/Globals.php index d05da9c94..e47f61803 100644 --- a/src/lib/Smr/Globals.php +++ b/src/lib/Smr/Globals.php @@ -320,7 +320,7 @@ public static function getBuyShipNameHREF(): string { } /** - * @return array + * @return array{text: int, html: int, logo: int} */ public static function getBuyShipNameCosts(): array { return [ diff --git a/src/lib/Smr/Port.php b/src/lib/Smr/Port.php index 6a0809849..360ada9c8 100644 --- a/src/lib/Smr/Port.php +++ b/src/lib/Smr/Port.php @@ -1331,7 +1331,7 @@ public function update(): void { } /** - * @param array $targetPlayers + * @param non-empty-array $targetPlayers * @return PortCombatResults */ public function shootPlayers(array $targetPlayers): array { diff --git a/src/lib/Smr/Routes/Route.php b/src/lib/Smr/Routes/Route.php index f8c1c854b..fd01bf6eb 100644 --- a/src/lib/Smr/Routes/Route.php +++ b/src/lib/Smr/Routes/Route.php @@ -30,7 +30,7 @@ abstract public function containsPort(int $sectorID): bool; /** * Recurse through the Route tree to get an ordered list. * - * @return array + * @return non-empty-list */ abstract public function getOneWayRoutes(): array; diff --git a/src/lib/Smr/Routes/RouteIterator.php b/src/lib/Smr/Routes/RouteIterator.php index a8782e120..a59bb2f9d 100644 --- a/src/lib/Smr/Routes/RouteIterator.php +++ b/src/lib/Smr/Routes/RouteIterator.php @@ -11,6 +11,7 @@ */ class RouteIterator { + /** @var InfiniteIterator> */ private InfiniteIterator $routeIterator; private TransactionType $transaction = TransactionType::Buy; diff --git a/test/SmrTest/lib/BarDrinkTest.php b/test/SmrTest/lib/BarDrinkTest.php index c4ce17c80..ea8f84fdf 100644 --- a/test/SmrTest/lib/BarDrinkTest.php +++ b/test/SmrTest/lib/BarDrinkTest.php @@ -46,7 +46,7 @@ public function test_isSpecial(): void { public function test_getSpecialMessage(): void { // every special drink has a special message foreach (BarDrink::getSpecial() as $drink) { - self::assertIsString(BarDrink::getSpecialMessage($drink)); + self::assertNotEmpty(BarDrink::getSpecialMessage($drink)); } }