Skip to content

Commit 1817dd6

Browse files
authored
Update to PHPStan 2.0 (#1982)
* Update rector to 2.0 as well due to its PHPStan dependency. * Remove some `checkAlwaysTrue*` options that are now true by default. * Fix errors reported by PHPStan 2.0 (some typos, wrong types, and wide types).
1 parent 07bec22 commit 1817dd6

File tree

11 files changed

+18
-13
lines changed

11 files changed

+18
-13
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@
8181
"require-dev": {
8282
"fig-r/psr2r-sniffer": "2.1.1",
8383
"overtrue/phplint": "9.5.5",
84-
"phpstan/phpstan": "1.12.5",
84+
"phpstan/phpstan": "2.0.3",
8585
"phpunit/phpunit": "11.5.0",
8686
"phpunit/php-code-coverage": "11.0.8",
87-
"rector/rector": "0.15.13",
87+
"rector/rector": "2.0.0",
8888
"squizlabs/php_codesniffer": "3.11.2"
8989
}
9090
}

phpstan.neon.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ parameters:
1010
# Stricter analysis
1111
polluteScopeWithLoopInitialAssignments: false
1212
polluteScopeWithAlwaysIterableForeach: false
13-
checkAlwaysTrueCheckTypeFunctionCall: true
14-
checkAlwaysTrueInstanceof: true
15-
checkAlwaysTrueStrictComparison: true
1613
checkExplicitMixedMissingReturn: true
1714
checkFunctionNameCase: true
1815
checkInternalClassCaseSensitivity: true

src/lib/Default/alliance_pick.inc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ function get_draft_teams(int $gameId): array {
3636
}
3737
}
3838

39+
if (count($teams) === 0) {
40+
throw new Exception('No draft leaders have been selected yet.');
41+
}
42+
3943
// Determine the smallest team alliance size.
4044
$minSize = min(array_map(fn(array $i): int => $i['Size'], $teams));
4145

src/lib/Smr/AbstractPlayer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,9 @@ public function getBounties(): array {
20512051
return $this->bounties;
20522052
}
20532053

2054+
/**
2055+
* @phpstan-assert-if-false array{} $this->getBounties()
2056+
*/
20542057
public function hasBounties(): bool {
20552058
return count($this->getBounties()) > 0;
20562059
}

src/lib/Smr/Chess/Board.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Board {
1111

1212
/** @var array<value-of<Colour>, array<Castling>> */
1313
private array $canCastle;
14-
/** @var array{X: int, Y: int}> */
14+
/** @var array{X: int, Y: int} */
1515
private array $enPassantPawn;
1616
/** @var array<int, array<int, ?ChessPiece>> */
1717
private array $board;
@@ -190,7 +190,7 @@ public function canCastle(Colour $colour, Castling $type): bool {
190190
}
191191

192192
/**
193-
* @return array{'X': int, 'Y': int}
193+
* @return array{X: int, Y: int}
194194
*/
195195
public function getEnPassantPawn(): array {
196196
return $this->enPassantPawn;

src/lib/Smr/Chess/ChessPiece.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function isAttacking(Board $board, int $x, int $y): bool {
4343
}
4444

4545
/**
46-
* @return array<array{int, int}>>
46+
* @return array<array{int, int}>
4747
*/
4848
public function getPossibleMoves(Board $board, bool $attackingCheck = false): array {
4949
$moves = [];
@@ -139,7 +139,7 @@ public function getPossibleMoves(Board $board, bool $attackingCheck = false): ar
139139
}
140140

141141
/**
142-
* @param array{int, int} $moves
142+
* @param list<array{int, int}> $moves
143143
*/
144144
private function addMove(int $toX, int $toY, Board $board, array &$moves, bool $attackingCheck = true): bool {
145145
if ($board->isValidCoord($toX, $toY)) {

src/lib/Smr/Globals.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public static function getBuyShipNameHREF(): string {
320320
}
321321

322322
/**
323-
* @return array<string, int>
323+
* @return array{text: int, html: int, logo: int}
324324
*/
325325
public static function getBuyShipNameCosts(): array {
326326
return [

src/lib/Smr/Port.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ public function update(): void {
13311331
}
13321332

13331333
/**
1334-
* @param array<AbstractPlayer> $targetPlayers
1334+
* @param non-empty-array<int, AbstractPlayer> $targetPlayers
13351335
* @return PortCombatResults
13361336
*/
13371337
public function shootPlayers(array $targetPlayers): array {

src/lib/Smr/Routes/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ abstract public function containsPort(int $sectorID): bool;
3030
/**
3131
* Recurse through the Route tree to get an ordered list.
3232
*
33-
* @return array<OneWayRoute>
33+
* @return non-empty-list<OneWayRoute>
3434
*/
3535
abstract public function getOneWayRoutes(): array;
3636

src/lib/Smr/Routes/RouteIterator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
class RouteIterator {
1313

14+
/** @var InfiniteIterator<int, OneWayRoute, ArrayIterator<int, OneWayRoute>> */
1415
private InfiniteIterator $routeIterator;
1516

1617
private TransactionType $transaction = TransactionType::Buy;

0 commit comments

Comments
 (0)