From d1cda2cf7b92312266765eccf84d49e050c2d2fc Mon Sep 17 00:00:00 2001 From: florentdevk Date: Fri, 3 Jul 2026 21:12:05 +0200 Subject: [PATCH] chore: upgrade PHPStan to level 8 and fix chr() type errors --- phpstan.dist.neon | 2 +- src/Chess/Domain/Service/MoveValidator.php | 23 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index ab21566..a5d2160 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,5 +1,5 @@ parameters: - level: 6 + level: 8 paths: - src/Chess/ - tests/Chess/ \ No newline at end of file diff --git a/src/Chess/Domain/Service/MoveValidator.php b/src/Chess/Domain/Service/MoveValidator.php index a3c1a8f..4bdcf5c 100644 --- a/src/Chess/Domain/Service/MoveValidator.php +++ b/src/Chess/Domain/Service/MoveValidator.php @@ -6,6 +6,7 @@ use Chess\Domain\Exception\InvalidMoveException; use Chess\Domain\Model\Board; +use Chess\Domain\Value\Color; use Chess\Domain\Value\Move; use Chess\Domain\Value\PieceType; use Chess\Domain\Value\Square; @@ -101,12 +102,12 @@ private function validateKingMove(Square $from, Square $to): void } } - private function validatePawnMove(Square $from, Square $to, Board $board, \Chess\Domain\Value\Color $color): void + private function validatePawnMove(Square $from, Square $to, Board $board, Color $color): void { $fileDiff = abs(\ord($to->file()) - \ord($from->file())); $rankDiff = $to->rank() - $from->rank(); - $direction = \Chess\Domain\Value\Color::White === $color ? 1 : -1; - $startRank = \Chess\Domain\Value\Color::White === $color ? 2 : 7; + $direction = Color::White === $color ? 1 : -1; + $startRank = Color::White === $color ? 2 : 7; if (0 === $fileDiff && $rankDiff === $direction) { if (!$board->isEmpty($to)) { @@ -141,14 +142,14 @@ private function assertStraightPathClear(Square $from, Square $to, Board $board) $fileStep = $this->step(\ord($to->file()) - \ord($from->file())); $rankStep = $this->step($to->rank() - $from->rank()); - $file = \chr(\ord($from->file()) + $fileStep); + $fileIndex = \ord($from->file()) + $fileStep; $rank = $from->rank() + $rankStep; - while ($file !== $to->file() || $rank !== $to->rank()) { - if (!$board->isEmpty(new Square($file, $rank))) { + while (\chr($fileIndex & 0xFF) !== $to->file() || $rank !== $to->rank()) { + if (!$board->isEmpty(new Square(\chr($fileIndex & 0xFF), $rank))) { throw new InvalidMoveException('Path is not clear.'); } - $file = \chr(\ord($file) + $fileStep); + $fileIndex += $fileStep; $rank += $rankStep; } } @@ -158,14 +159,14 @@ private function assertDiagonalPathClear(Square $from, Square $to, Board $board) $fileStep = $this->step(\ord($to->file()) - \ord($from->file())); $rankStep = $this->step($to->rank() - $from->rank()); - $file = \chr(\ord($from->file()) + $fileStep); + $fileIndex = \ord($from->file()) + $fileStep; $rank = $from->rank() + $rankStep; - while ($file !== $to->file() || $rank !== $to->rank()) { - if (!$board->isEmpty(new Square($file, $rank))) { + while (\chr($fileIndex & 0xFF) !== $to->file() || $rank !== $to->rank()) { + if (!$board->isEmpty(new Square(\chr($fileIndex & 0xFF), $rank))) { throw new InvalidMoveException('Path is not clear.'); } - $file = \chr(\ord($file) + $fileStep); + $fileIndex += $fileStep; $rank += $rankStep; } }