Skip to content

Commit

Permalink
Update to PHPStan 2.0
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
hemberger committed Dec 13, 2024
1 parent 07bec22 commit a663b73
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ parameters:
# Stricter analysis
polluteScopeWithLoopInitialAssignments: false
polluteScopeWithAlwaysIterableForeach: false
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
checkAlwaysTrueStrictComparison: true
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Default/alliance_pick.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Check warning on line 40 in src/lib/Default/alliance_pick.inc.php

View check run for this annotation

Codecov / codecov/patch

src/lib/Default/alliance_pick.inc.php#L39-L40

Added lines #L39 - L40 were not covered by tests
}

// Determine the smallest team alliance size.
$minSize = min(array_map(fn(array $i): int => $i['Size'], $teams));

Expand Down
3 changes: 3 additions & 0 deletions src/lib/Smr/AbstractPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Smr/Chess/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Board {

/** @var array<value-of<Colour>, array<Castling>> */
private array $canCastle;
/** @var array{X: int, Y: int}> */
/** @var array{X: int, Y: int} */
private array $enPassantPawn;
/** @var array<int, array<int, ?ChessPiece>> */
private array $board;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Smr/Chess/ChessPiece.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isAttacking(Board $board, int $x, int $y): bool {
}

/**
* @return array<array{int, int}>>
* @return array<array{int, int}>
*/
public function getPossibleMoves(Board $board, bool $attackingCheck = false): array {
$moves = [];
Expand Down Expand Up @@ -139,7 +139,7 @@ public function getPossibleMoves(Board $board, bool $attackingCheck = false): ar
}

/**
* @param array{int, int} $moves
* @param list<array{int, int}> $moves
*/
private function addMove(int $toX, int $toY, Board $board, array &$moves, bool $attackingCheck = true): bool {
if ($board->isValidCoord($toX, $toY)) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Smr/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static function getBuyShipNameHREF(): string {
}

/**
* @return array<string, int>
* @return array{text: int, html: int, logo: int}
*/
public static function getBuyShipNameCosts(): array {
return [
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Smr/Port.php
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ public function update(): void {
}

/**
* @param array<AbstractPlayer> $targetPlayers
* @param non-empty-array<int, AbstractPlayer> $targetPlayers
* @return PortCombatResults
*/
public function shootPlayers(array $targetPlayers): array {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Smr/Routes/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract public function containsPort(int $sectorID): bool;
/**
* Recurse through the Route tree to get an ordered list.
*
* @return array<OneWayRoute>
* @return non-empty-list<OneWayRoute>
*/
abstract public function getOneWayRoutes(): array;

Expand Down
1 change: 1 addition & 0 deletions src/lib/Smr/Routes/RouteIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
class RouteIterator {

/** @var InfiniteIterator<int, OneWayRoute, ArrayIterator<int, OneWayRoute>> */
private InfiniteIterator $routeIterator;

private TransactionType $transaction = TransactionType::Buy;
Expand Down
2 changes: 1 addition & 1 deletion test/SmrTest/lib/BarDrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit a663b73

Please sign in to comment.