diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index a173f88..d857b1b 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -13,7 +13,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: "8.3" - tools: phpcs:3.8, php-cs-fixer:3.49, phpstan:1.10 + tools: phpcs:3.9, php-cs-fixer:3.56, phpstan:1.11 coverage: none env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -45,7 +45,7 @@ jobs: with: php-version: "8.3" extensions: mbstring, bcmath, xdebug - tools: phpunit:11.0 + tools: phpunit:11.1 coverage: xdebug env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 4f97b76..f106fe0 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -3,7 +3,7 @@ /** * php-cs-fixer configuration file. * - * minimum version: ^3.49 + * minimum version: ^3.56 * * @see https://cs.symfony.com/doc/config.html */ diff --git a/phpcs.xml b/phpcs.xml index 1548ca6..603a46a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -2,13 +2,13 @@ PHP_CodeSniffer configuration - + diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 05c9fdb..33d8dd5 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,6 +1,6 @@ # PHPStan configuration file. # -# minimum version: ^1.10.57 +# minimum version: ^1.11 # # @see https://phpstan.org/config-reference parameters: @@ -16,7 +16,8 @@ parameters: - .tools - vendor ignoreErrors: - - '#^Static method TBali[a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) is unused.$#' - - '#^Method TBali[a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) is unused.$#' + - + message: '#^(Static )?[Mm]ethod TBali[a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) is unused.$#' + identifier: method.unused includes: - phar://phpstan.phar/conf/bleedingEdge.neon diff --git a/phpunit.xml b/phpunit.xml index ba214fa..80d2468 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,13 +2,13 @@ 0) { $messages[] = $countFails . ' failed'; } - // @ phpstan-ignore-next-line if ($countSkipped > 0) { $messages[] = $countSkipped . ' skipped'; } - // @ phpstan-ignore-next-line if (($countFails > 0) or ($countSkipped > 0)) { $failSkipMsg = ' (' . implode(', ', $messages) . ')'; } else { diff --git a/src/Aoc2015/Aoc2015Day12.php b/src/Aoc2015/Aoc2015Day12.php index 2737a6c..a66c4f0 100644 --- a/src/Aoc2015/Aoc2015Day12.php +++ b/src/Aoc2015/Aoc2015Day12.php @@ -39,7 +39,7 @@ public function solve(array $input): array // ---------- Part 1 $a = json_decode($input, true) ?? []; // true: JSON objects will be returned as associative arrays $count = 0; - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type array_walk_recursive($a, static function ($x) use (&$count): void { if (is_numeric($x)) { $count += intval($x); @@ -59,7 +59,7 @@ private function sumNonRed(mixed $a): int } if (is_object($a)) { $isOk = true; - // @phpstan-ignore-next-line + // @phpstan-ignore foreach.nonIterable foreach ($a as $item) { if ($item == 'red') { $isOk = false; @@ -74,7 +74,7 @@ private function sumNonRed(mixed $a): int return 0; } $sum = 0; - // @phpstan-ignore-next-line + // @phpstan-ignore foreach.nonIterable foreach ($a as $item) { $sum += $this->sumNonRed($item); } diff --git a/src/Aoc2016/Aoc2016Day08.php b/src/Aoc2016/Aoc2016Day08.php index 92efe66..6ce895a 100644 --- a/src/Aoc2016/Aoc2016Day08.php +++ b/src/Aoc2016/Aoc2016Day08.php @@ -147,7 +147,7 @@ public function simulate(Instruction $instr): void } return; } - // @phpstan-ignore-next-line + // @phpstan-ignore equal.alwaysTrue if ($instr->verb == InstructionVerb::RotateColumn) { for ($i = 0; $i < $instr->y; ++$i) { $temp = $this->grid[self::MAX_Y - 1][$instr->x]; diff --git a/src/Aoc2017/Aoc2017Day18.php b/src/Aoc2017/Aoc2017Day18.php index 6ac57a7..ea1f5c5 100644 --- a/src/Aoc2017/Aoc2017Day18.php +++ b/src/Aoc2017/Aoc2017Day18.php @@ -50,13 +50,13 @@ public function solve(array $input): array $wasComm = false; $thread0->execute(); while (count($thread0->sndQueue) > 0) { - // @phpstan-ignore-next-line + // @phpstan-ignore assign.propertyType $thread1->rcvQueue[] = array_shift($thread0->sndQueue); $wasComm = true; } $thread1->execute(); while (count($thread1->sndQueue) > 0) { - // @phpstan-ignore-next-line + // @phpstan-ignore assign.propertyType $thread0->rcvQueue[] = array_shift($thread1->sndQueue); $wasComm = true; } diff --git a/src/Aoc2017/Aoc2017Day20.php b/src/Aoc2017/Aoc2017Day20.php index 3a6e989..b0ec17e 100644 --- a/src/Aoc2017/Aoc2017Day20.php +++ b/src/Aoc2017/Aoc2017Day20.php @@ -83,7 +83,7 @@ public function solve(array $input): array $collisions[$particle->id] = true; } if (count($collisions) > 0) { - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-- T = ' . $t . ': remaining particles = ' . count($particles) . PHP_EOL; diff --git a/src/Aoc2017/Aoc2017Day21.php b/src/Aoc2017/Aoc2017Day21.php index 1c264c7..f7b57d3 100644 --- a/src/Aoc2017/Aoc2017Day21.php +++ b/src/Aoc2017/Aoc2017Day21.php @@ -154,7 +154,7 @@ private static function getOrientations(string $image): array private static function printImage(string $image): void { $size = intval(round(sqrt(strlen($image)))); - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type echo implode(PHP_EOL, str_split($image, $size)), PHP_EOL; } } diff --git a/src/Aoc2018/Aoc2018Day09.php b/src/Aoc2018/Aoc2018Day09.php index d476993..4b09300 100644 --- a/src/Aoc2018/Aoc2018Day09.php +++ b/src/Aoc2018/Aoc2018Day09.php @@ -39,7 +39,7 @@ public function solve(array $input): array { // ---------- Parse input $a = explode(' ', $input[0] ?? ''); - $countPlayers = intval($a[0] ?? '0'); + $countPlayers = intval($a[0]); $lastMarble = intval($a[6] ?? '0'); // ---------- Part 1 + 2 $part2multiplier = $lastMarble > 10_000 ? 100 : 1; diff --git a/src/Aoc2018/Aoc2018Day10.php b/src/Aoc2018/Aoc2018Day10.php index 05e564b..ab5cd25 100644 --- a/src/Aoc2018/Aoc2018Day10.php +++ b/src/Aoc2018/Aoc2018Day10.php @@ -46,7 +46,7 @@ public function solve(array $input): array if ($swarm->area > $area) { $swarm->backTick(); $ans2 = $swarm->step; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DISPLAY) { // @codeCoverageIgnoreStart $swarm->display(); diff --git a/src/Aoc2018/Aoc2018Day15.php b/src/Aoc2018/Aoc2018Day15.php index d74086d..2a381dc 100644 --- a/src/Aoc2018/Aoc2018Day15.php +++ b/src/Aoc2018/Aoc2018Day15.php @@ -114,7 +114,7 @@ private function simulate(int $elfAttack = 3): array $elvesDied = 0; $winnerSide = ''; $survivors = []; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse,logicalAnd.leftAlwaysFalse if (self::DEBUG and ($elfAttack == 3)) { // @codeCoverageIgnoreStart echo '---- Starting state', PHP_EOL; @@ -261,7 +261,7 @@ private function simulate(int $elfAttack = 3): array static fn (Creature $c): int => $c->hp, $survivors, )); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-- With ' . $elfAttack . ' elf attack power: ' . $elvesDied . ' elves died. Winner team is ' diff --git a/src/Aoc2018/Aoc2018Day16.php b/src/Aoc2018/Aoc2018Day16.php index 602be16..647fae4 100644 --- a/src/Aoc2018/Aoc2018Day16.php +++ b/src/Aoc2018/Aoc2018Day16.php @@ -92,7 +92,7 @@ public function solve(array $input): array // ---------- Part 2 $ans2 = 0; $matchings = []; - // @phpstan-ignore-next-line + // @phpstan-ignore smaller.alwaysTrue while (count($matchings) < self::MAX_OPCODE) { for ($opcode = 0; $opcode < self::MAX_OPCODE; ++$opcode) { if (isset($matchings[$opcode])) { @@ -112,7 +112,7 @@ public function solve(array $input): array } } } - // @phpstan-ignore-next-line + // @phpstan-ignore deadCode.unreachable $regs = [0, 0, 0, 0]; foreach ($instructions as $instruction) { $regs = self::execute($matchings[$instruction[0]], $instruction, $regs); diff --git a/src/Aoc2018/Aoc2018Day17.php b/src/Aoc2018/Aoc2018Day17.php index 597b2ad..f5d1ec4 100644 --- a/src/Aoc2018/Aoc2018Day17.php +++ b/src/Aoc2018/Aoc2018Day17.php @@ -115,7 +115,7 @@ private function flow(int $x, int $y): bool return false; } $this->flows[$y][$x] = true; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '---- FLOW @' . $x . ',' . $y . PHP_EOL; @@ -162,7 +162,7 @@ private function flow(int $x, int $y): bool } } if (!$canFill) { - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '---- END FLOW @' . $x . ',' . $y . PHP_EOL; @@ -179,7 +179,7 @@ private function flow(int $x, int $y): bool $x1 += $dx; } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '---- END WATER @' . $x . ',' . $y . PHP_EOL; diff --git a/src/Aoc2018/Aoc2018Day19.php b/src/Aoc2018/Aoc2018Day19.php index 46cf056..39591db 100644 --- a/src/Aoc2018/Aoc2018Day19.php +++ b/src/Aoc2018/Aoc2018Day19.php @@ -52,7 +52,7 @@ public function solve(array $input): array // ---------- Part 1 $regs = array_fill(0, 6, 0); $target1 = 0; - // @phpstan-ignore-next-line + // @phpstan-ignore logicalOr.rightAlwaysFalse if ((count($instructions) == 7) or self::SIM_PART1) { $ip = 0; while (true) { @@ -87,15 +87,15 @@ public function solve(array $input): array $regs = array_fill(0, 6, 0); $regs[0] = 1; $target2 = 0; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SIM_PART2) { $ip = 0; $maxSteps = 150; while (true) { - // @phpstan-ignore-next-line + // @phpstan-ignore equal.alwaysTrue if (($ip == 35) and ($target2 == 0)) { $target2 = $regs[2]; - // @phpstan-ignore-next-line + // @phpstan-ignore booleanNot.alwaysTrue if (!self::DISPLAY_TRACE) { break; } @@ -103,7 +103,7 @@ public function solve(array $input): array if (($ip < 0) or ($ip >= count($instructions))) { break; } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DISPLAY_TRACE) { echo $ip . ' : ' . implode(' ', $instructions[$ip]) . ' : [' . implode(', ', $regs) . '] ', PHP_EOL; } diff --git a/src/Aoc2018/Aoc2018Day21.php b/src/Aoc2018/Aoc2018Day21.php index 0e862b2..620c582 100644 --- a/src/Aoc2018/Aoc2018Day21.php +++ b/src/Aoc2018/Aoc2018Day21.php @@ -52,7 +52,7 @@ public function solve(array $input): array // ---------- Part 1 + 2 $ans1 = 0; $ans2 = 0; - // @phpstan-ignore-next-line + // @phpstan-ignore booleanNot.alwaysTrue if (!self::SIM) { $c1 = $instructions[7][1]; $c2 = $instructions[11][2]; @@ -68,7 +68,7 @@ public function solve(array $input): array $r5 = ((($r5 + ($r4 & 0xFF)) & 0xFFFFFF) * $c2) & 0xFFFFFF; $r4 >>= 8; $r5 = ((($r5 + ($r4 & 0xFF)) & 0xFFFFFF) * $c2) & 0xFFFFFF; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse,logicalAnd.leftAlwaysFalse if (self::DEBUG and ($step < $maxSteps)) { // @codeCoverageIgnoreStart echo '#' . $step . ': 0x' . str_pad(dechex($r5), 8, '0', STR_PAD_LEFT), PHP_EOL; @@ -88,7 +88,7 @@ public function solve(array $input): array return [strval($ans1), strval($ans2)]; } // @codeCoverageIgnoreStart - // @phpstan-ignore-next-line + // @phpstan-ignore deadCode.unreachable $maxSteps = 5; $regs = array_fill(0, 6, 0); $prev = 0; diff --git a/src/Aoc2018/Aoc2018Day23.php b/src/Aoc2018/Aoc2018Day23.php index a1c543f..715e302 100644 --- a/src/Aoc2018/Aoc2018Day23.php +++ b/src/Aoc2018/Aoc2018Day23.php @@ -79,7 +79,7 @@ public function solve(array $input): array if ($pq->isEmpty()) { throw new \Exception('No solution found'); } - // @phpstan-ignore-next-line + // @phpstan-ignore offsetAccess.nonArray [$count, $size, $dist, $cornerLow, $cornerHigh] = $pq->extract(); if ($size == 1) { $ans2 = $dist; @@ -119,7 +119,7 @@ public function __construct( public function manhattanToOrigo(): int { - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type return intval(array_sum(array_map(abs(...), $this->p))); } } @@ -147,7 +147,7 @@ public function inRange(Point $point): bool public function maxRangeCoord(): int { - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type return intval(max(array_map(abs(...), $this->p))) + $this->r; } diff --git a/src/Aoc2018/Aoc2018Day24.php b/src/Aoc2018/Aoc2018Day24.php index c037f47..d38bf47 100644 --- a/src/Aoc2018/Aoc2018Day24.php +++ b/src/Aoc2018/Aoc2018Day24.php @@ -161,7 +161,7 @@ private function simulate(array $groups): array } // attacking phase usort($aliveGroups, static fn (ArmyGroup $a, ArmyGroup $b): int => $b->initiative <=> $a->initiative); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { echo '---- starting attacking phase', PHP_EOL; foreach ($aliveGroups as $g) { @@ -181,7 +181,7 @@ private function simulate(array $groups): array $killed = intval(min(intdiv($damage, $defender->hp), $defender->units)); $totalKills += $killed; $defender->units -= $killed; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo ' #' . $attacker->id . ' hits #' . $defender->id @@ -194,7 +194,7 @@ private function simulate(array $groups): array break; } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-------- surviving groups', PHP_EOL; diff --git a/src/Aoc2019/Aoc2019Day11.php b/src/Aoc2019/Aoc2019Day11.php index e78904b..41b5d52 100644 --- a/src/Aoc2019/Aoc2019Day11.php +++ b/src/Aoc2019/Aoc2019Day11.php @@ -92,7 +92,7 @@ private function solvePart(array $memory, int $startTile = 0): int foreach ($grid as $row) { $ans += count($row); } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse,logicalAnd.rightAlwaysFalse if (($startTile == 1) and self::SHOW_PAINT) { for ($y = $minY; $y <= $maxY; ++$y) { $s = ''; diff --git a/src/Aoc2019/Aoc2019Day13.php b/src/Aoc2019/Aoc2019Day13.php index 9382409..1323e74 100644 --- a/src/Aoc2019/Aoc2019Day13.php +++ b/src/Aoc2019/Aoc2019Day13.php @@ -79,7 +79,7 @@ private function solvePart1(array $memory): int } } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_ARCADE) { // @codeCoverageIgnoreStart for ($y = 0; $y <= $maxY; ++$y) { @@ -134,7 +134,7 @@ private function solvePart2(array $memory): int } } $startOutput = count($robot->outputs); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_ARCADE) { // @codeCoverageIgnoreStart echo '-----------', PHP_EOL, PHP_EOL; diff --git a/src/Aoc2019/Aoc2019Day15.php b/src/Aoc2019/Aoc2019Day15.php index b8808af..77411d6 100644 --- a/src/Aoc2019/Aoc2019Day15.php +++ b/src/Aoc2019/Aoc2019Day15.php @@ -73,7 +73,7 @@ public function solve(array $input): array } } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_MAP) { // @codeCoverageIgnoreStart $map->printMap($oxygenX, $oxygenY); diff --git a/src/Aoc2019/Aoc2019Day17.php b/src/Aoc2019/Aoc2019Day17.php index e0924be..13938d5 100644 --- a/src/Aoc2019/Aoc2019Day17.php +++ b/src/Aoc2019/Aoc2019Day17.php @@ -77,7 +77,7 @@ public function solve(array $input): array } $maxX = strlen($grid[0]); $maxY = count($grid); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart foreach ($grid as $line) { @@ -163,7 +163,7 @@ public function solve(array $input): array for ($i = 0; $i < 3; ++$i) { $commandStr2 = str_replace($selectedFunctions[$i], chr(ord('A') + $i), $commandStr2); } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '--- extended command list:', PHP_EOL; diff --git a/src/Aoc2019/Aoc2019Day25.php b/src/Aoc2019/Aoc2019Day25.php index 16f6524..cfa2271 100644 --- a/src/Aoc2019/Aoc2019Day25.php +++ b/src/Aoc2019/Aoc2019Day25.php @@ -114,7 +114,7 @@ public function solve(array $input): array $memory = array_map(intval(...), explode(',', $input[0])); // ---------- Part 1 $ans1 = self::SOLUTIONS[0]; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysTrue if (self::PLAY_GAME) { $game = new AdventureSimulator($memory); foreach (self::INSTRUCTIONS as $line) { @@ -123,7 +123,7 @@ public function solve(array $input): array if ($output == '') { return ['0', '0']; } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_OUTPUT) { echo $output, PHP_EOL; echo $line, PHP_EOL; @@ -131,7 +131,7 @@ public function solve(array $input): array $game->stringInput($line); } $output = $game->stringOutput(); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_OUTPUT) { echo $output, PHP_EOL; } @@ -139,7 +139,7 @@ public function solve(array $input): array for ($i = 0; $i < count(self::ITEMS); ++$i) { if ((($bitmask >> $i) & 1) != 0) { $game->stringInput('take ' . self::ITEMS[$i]); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_OUTPUT) { echo 'take ' . self::ITEMS[$i], PHP_EOL; } @@ -148,7 +148,7 @@ public function solve(array $input): array $game->stringInput('north'); $game->simulate(); $output = $game->stringOutput(); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_OUTPUT) { echo $output, PHP_EOL; } @@ -162,7 +162,7 @@ public function solve(array $input): array for ($i = 0; $i < count(self::ITEMS); ++$i) { if ((($bitmask >> $i) & 1) != 0) { $game->stringInput('drop ' . self::ITEMS[$i]); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_OUTPUT) { echo 'drop ' . self::ITEMS[$i], PHP_EOL; } diff --git a/src/Aoc2020/Aoc2020Day06.php b/src/Aoc2020/Aoc2020Day06.php index 07f2dc2..321f23e 100644 --- a/src/Aoc2020/Aoc2020Day06.php +++ b/src/Aoc2020/Aoc2020Day06.php @@ -47,7 +47,7 @@ public function solve(array $input): array // ---------- Part 1 $ans1 = array_sum(array_map( // count_chars mode = 3: a string containing all unique characters is returned. - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type static fn (array $group): int => strlen(count_chars(implode('', $group), 3)), $processedInput )); @@ -56,7 +56,7 @@ public function solve(array $input): array // count_chars mode = 1: an array with the byte-value as key and the frequency of every byte as value, // only byte-values with a frequency greater than zero are listed. static fn (array $group): int => count(array_filter( - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type count_chars(implode('', $group), 1), static fn (int $value): bool => $value == count($group), )), diff --git a/src/Aoc2020/Aoc2020Day14.php b/src/Aoc2020/Aoc2020Day14.php index 101795b..5d5a7f3 100644 --- a/src/Aoc2020/Aoc2020Day14.php +++ b/src/Aoc2020/Aoc2020Day14.php @@ -60,9 +60,10 @@ public function solve(array $input): array $maskedValue = 0; for ($i = 0; $i < self::BIT_SIZE; ++$i) { match ($mask[$i]) { - '0' => 0, // @phpstan-ignore-line - '1' => $maskedValue |= (1 << (self::BIT_SIZE - 1 - $i)), // @phpstan-ignore-line - 'X' => $maskedValue |= ($value & (1 << (self::BIT_SIZE - 1 - $i))), // @phpstan-ignore-line + '0' => 0, // @phpstan-ignore match.alwaysFalse + '1' => $maskedValue |= (1 << (self::BIT_SIZE - 1 - $i)), // @phpstan-ignore match.alwaysFalse + // @phpstan-ignore match.alwaysTrue + 'X' => $maskedValue |= ($value & (1 << (self::BIT_SIZE - 1 - $i))), default => throw new \Exception('Invalid mask'), }; } @@ -98,9 +99,10 @@ public function solve(array $input): array $floatingBits = []; for ($i = 0; $i < self::BIT_SIZE; ++$i) { match ($mask[$i]) { - '0' => $maskedLoc |= ($loc & (1 << (self::BIT_SIZE - 1 - $i))), // @phpstan-ignore-line - '1' => $maskedLoc |= (1 << (self::BIT_SIZE - 1 - $i)), // @phpstan-ignore-line - 'X' => $floatingBits[] = self::BIT_SIZE - 1 - $i, // @phpstan-ignore-line + // @phpstan-ignore match.alwaysFalse + '0' => $maskedLoc |= ($loc & (1 << (self::BIT_SIZE - 1 - $i))), + '1' => $maskedLoc |= (1 << (self::BIT_SIZE - 1 - $i)), // @phpstan-ignore match.alwaysFalse + 'X' => $floatingBits[] = self::BIT_SIZE - 1 - $i, // @phpstan-ignore match.alwaysTrue default => throw new \Exception('Invalid mask'), }; } diff --git a/src/Aoc2020/Aoc2020Day19.php b/src/Aoc2020/Aoc2020Day19.php index 44b6924..bbaad4a 100644 --- a/src/Aoc2020/Aoc2020Day19.php +++ b/src/Aoc2020/Aoc2020Day19.php @@ -72,7 +72,7 @@ public function solve(array $input): array throw new \Exception('No solution found'); // @codeCoverageIgnoreEnd } - // @phpstan-ignore-next-line + // @phpstan-ignore deadCode.unreachable $len42 = strlen(array_key_first($this->generates[42])); $len31 = strlen(array_key_first($this->generates[31])); foreach ($this->messages as $message) { diff --git a/src/Aoc2020/Aoc2020Day20.php b/src/Aoc2020/Aoc2020Day20.php index 0ff9953..9834df0 100644 --- a/src/Aoc2020/Aoc2020Day20.php +++ b/src/Aoc2020/Aoc2020Day20.php @@ -105,7 +105,7 @@ public function solve(array $input): array throw new \Exception('No solution found'); // @codeCoverageIgnoreEnd } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '--- Reconstructed tiles:', PHP_EOL; @@ -690,7 +690,7 @@ public function findMonsters(Image $monsterImage): int static fn (string $line): int => substr_count($line, '#'), $this->grid, )); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (Aoc2020Day20::DEBUG) { // @codeCoverageIgnoreStart echo '--- Image with proper orientation:', PHP_EOL; diff --git a/src/Aoc2020/Aoc2020Day22.php b/src/Aoc2020/Aoc2020Day22.php index ab8a22d..9a5cfbb 100644 --- a/src/Aoc2020/Aoc2020Day22.php +++ b/src/Aoc2020/Aoc2020Day22.php @@ -98,7 +98,7 @@ private function parseInput(array $input): array throw new \Exception('Invalid input'); // @codeCoverageIgnoreEnd } - // @phpstan-ignore-next-line + // @phpstan-ignore return.type return $ans; } } diff --git a/src/Aoc2021/Aoc2021Day10.php b/src/Aoc2021/Aoc2021Day10.php index ebcbca5..5fbc7d9 100644 --- a/src/Aoc2021/Aoc2021Day10.php +++ b/src/Aoc2021/Aoc2021Day10.php @@ -70,7 +70,7 @@ public function solve(array $input): array $score = 0; while (count($stack) > 0) { $opening = array_pop($stack); - $score = $score * 5 + (self::SCORES_PART2[self::MATCHING_CLOSE[$opening]] ?? 0); + $score = $score * 5 + self::SCORES_PART2[self::MATCHING_CLOSE[$opening]]; } $scores[] = $score; } diff --git a/src/Aoc2021/Aoc2021Day13.php b/src/Aoc2021/Aoc2021Day13.php index 717e5c9..fb0b721 100644 --- a/src/Aoc2021/Aoc2021Day13.php +++ b/src/Aoc2021/Aoc2021Day13.php @@ -81,7 +81,7 @@ public function solve(array $input): array foreach ($dots as $dot) { $grid[$dot[1]][$dot[0]] = '#'; } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_GRID) { // @codeCoverageIgnoreStart foreach ($grid as $line) { diff --git a/src/Aoc2021/Aoc2021Day18.php b/src/Aoc2021/Aoc2021Day18.php index 349aa9b..6e98d78 100644 --- a/src/Aoc2021/Aoc2021Day18.php +++ b/src/Aoc2021/Aoc2021Day18.php @@ -182,7 +182,7 @@ public function explode(): bool throw new \Exception('Impossible'); // @codeCoverageIgnoreEnd } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-- exploding node: ' . $node->toString(), PHP_EOL; @@ -234,7 +234,7 @@ public function split(): bool if ($this->value < self::MAX_VALUE) { return false; } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-- splitting node: ' . $this->toString(), PHP_EOL; @@ -264,7 +264,7 @@ public function split(): bool public function reduce(): self { while (true) { - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '-- trying to reduce ' . $this->toString(), PHP_EOL; diff --git a/src/Aoc2021/Aoc2021Day23.php b/src/Aoc2021/Aoc2021Day23.php index 1ac9ae2..991ac63 100644 --- a/src/Aoc2021/Aoc2021Day23.php +++ b/src/Aoc2021/Aoc2021Day23.php @@ -84,7 +84,7 @@ public function solvePart(Burrow $burrow, int $startStateRoom, int $startStateHa } if (($stateRoom == $burrow->targetStateRoom) and ($stateHallway == $burrow->targetStateHallway)) { $ans = $totalCost; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo ' Total cost: ' . $ans, PHP_EOL; diff --git a/src/Aoc2021/Aoc2021Day24.php b/src/Aoc2021/Aoc2021Day24.php index 895cfb4..926fcf1 100644 --- a/src/Aoc2021/Aoc2021Day24.php +++ b/src/Aoc2021/Aoc2021Day24.php @@ -50,7 +50,7 @@ public function solve(array $input): array $q[] = intval(substr($input[$i * 18 + 5], 6)); $r[] = intval(substr($input[$i * 18 + 15], 6)); } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_EMULATION) { // @codeCoverageIgnoreStart // -- 01234567890123 diff --git a/src/Aoc2022/Aoc2022Day01.php b/src/Aoc2022/Aoc2022Day01.php index 08584e2..6366813 100644 --- a/src/Aoc2022/Aoc2022Day01.php +++ b/src/Aoc2022/Aoc2022Day01.php @@ -47,7 +47,7 @@ public function solve(array $input): array $cals = array_map(array_sum(...), $calories); $ans1 = max($cals); rsort($cals); - $ans2 = ($cals[0] ?? 0) + ($cals[1] ?? 0) + ($cals[2] ?? 0); + $ans2 = $cals[0] + ($cals[1] ?? 0) + ($cals[2] ?? 0); return [strval($ans1), strval($ans2)]; } } diff --git a/src/Aoc2022/Aoc2022Day06.php b/src/Aoc2022/Aoc2022Day06.php index fe88677..859bc37 100644 --- a/src/Aoc2022/Aoc2022Day06.php +++ b/src/Aoc2022/Aoc2022Day06.php @@ -48,7 +48,7 @@ private function solvePart(string $data, int $markerWidth): int for ($i = $markerWidth; $i <= strlen($data); ++$i) { $cand = substr($data, $i - $markerWidth, $markerWidth); // count_chars mode = 3: a string containing all unique characters is returned. - // @phpstan-ignore-next-line + // @phpstan-ignore argument.type if (strlen(count_chars($cand, 3)) == $markerWidth) { return $i; } diff --git a/src/Aoc2022/Aoc2022Day10.php b/src/Aoc2022/Aoc2022Day10.php index 01d57ba..f5345af 100644 --- a/src/Aoc2022/Aoc2022Day10.php +++ b/src/Aoc2022/Aoc2022Day10.php @@ -87,7 +87,7 @@ public function solve(array $input): array $screen[$screenY][$screenX] = '#'; } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::SHOW_SCREEN) { // @codeCoverageIgnoreStart foreach ($screen as $row) { diff --git a/src/Aoc2022/Aoc2022Day14.php b/src/Aoc2022/Aoc2022Day14.php index 17adbc9..91d7146 100644 --- a/src/Aoc2022/Aoc2022Day14.php +++ b/src/Aoc2022/Aoc2022Day14.php @@ -77,7 +77,7 @@ public function solve(array $input): array $canFall = false; foreach ([[0, 1], [-1, 1], [1, 1]] as [$dx, $dy]) { [$x1, $y1] = [$x + $dx, $y + $dy]; - // @phpstan-ignore-next-line + // @phpstan-ignore isset.offset if (!isset($walls[$y1][$x1]) and !isset($sands[$y1][$x1])) { $canFall = true; break; diff --git a/src/Aoc2022/Aoc2022Day15.php b/src/Aoc2022/Aoc2022Day15.php index 4960893..29cf5d8 100644 --- a/src/Aoc2022/Aoc2022Day15.php +++ b/src/Aoc2022/Aoc2022Day15.php @@ -73,7 +73,7 @@ public function solve(array $input): array $half = intdiv($maxCoord, 2); $bigRect = Rect::fromXY(-$half, $half, $maxCoord + $half, $half); $possibles = [$bigRect]; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo 'BigRect: ' . $bigRect->toString(), PHP_EOL; @@ -86,7 +86,7 @@ public function solve(array $input): array $newPossibles = array_merge($newPossibles, $possible->diff($invalidRect)); } $possibles = $newPossibles; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse,logicalAnd.leftAlwaysFalse if (self::DEBUG and ($maxCoord == self::MAX_COORD_EXAMPLE)) { // @codeCoverageIgnoreStart echo '---- Removing locations based on sensor #' . $idxSensor . ': ' . $sensor->toString() diff --git a/src/Aoc2022/Aoc2022Day17.php b/src/Aoc2022/Aoc2022Day17.php index 0ae70bf..33d16bb 100644 --- a/src/Aoc2022/Aoc2022Day17.php +++ b/src/Aoc2022/Aoc2022Day17.php @@ -160,7 +160,7 @@ public function simulate(int $maxTurn = 1): int $rock = $this->rocks[$this->idxNextRock]; $this->idxNextRock = ($this->idxNextRock + 1) % count($this->rocks); $this->simRock($rock); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '--- Pit after turn #' . $turn, PHP_EOL; diff --git a/src/Aoc2023/Aoc2023Day10.php b/src/Aoc2023/Aoc2023Day10.php index 40809a8..a9a532e 100644 --- a/src/Aoc2023/Aoc2023Day10.php +++ b/src/Aoc2023/Aoc2023Day10.php @@ -235,7 +235,7 @@ public function solve(array $input): array } } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '---- start: (' . $startX . ', ' . $startY . ')', PHP_EOL; diff --git a/src/Aoc2023/Aoc2023Day14.php b/src/Aoc2023/Aoc2023Day14.php index b7c4d14..aba76e2 100644 --- a/src/Aoc2023/Aoc2023Day14.php +++ b/src/Aoc2023/Aoc2023Day14.php @@ -84,9 +84,9 @@ private function parseInput(array $input): void for ($x = 0; $x < $this->maxX; ++$x) { $c = $this->grid[$y][$x]; if ($c == '#') { - // @phpstan-ignore-next-line + // @phpstan-ignore assign.propertyType $this->fixRocksAtX[$x][] = [$x, $y]; - // @phpstan-ignore-next-line + // @phpstan-ignore assign.propertyType $this->fixRocksAtY[$y][] = [$x, $y]; } elseif (($c != '.') and ($c != 'O')) { throw new \Exception('Invalid input'); diff --git a/src/Aoc2023/Aoc2023Day17.php b/src/Aoc2023/Aoc2023Day17.php index 14c833d..1b5e4fd 100644 --- a/src/Aoc2023/Aoc2023Day17.php +++ b/src/Aoc2023/Aoc2023Day17.php @@ -88,7 +88,7 @@ private function solvePart(int $part = 1): int and (($part == 1) or ($steps >= 4)) ) { $ans = $totalCost; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse,logicalAnd.leftAlwaysFalse if (self::DEBUG and ($part == 2)) { // @codeCoverageIgnoreStart echo '--- [' . $this->maxX . ' x ' . $this->maxY . '] Part #' . $part . ' : ' . $ans, PHP_EOL; diff --git a/src/Aoc2023/Aoc2023Day18.php b/src/Aoc2023/Aoc2023Day18.php index 035e91f..6069d65 100644 --- a/src/Aoc2023/Aoc2023Day18.php +++ b/src/Aoc2023/Aoc2023Day18.php @@ -108,7 +108,7 @@ public function solve(array $input): array } } $ans1 = ($maxX - $minX + 3) * ($maxY - $minY + 3) - count($outsideBlocks); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo PHP_EOL; diff --git a/src/Aoc2023/Aoc2023Day20.php b/src/Aoc2023/Aoc2023Day20.php index b522d1a..c7b83f3 100644 --- a/src/Aoc2023/Aoc2023Day20.php +++ b/src/Aoc2023/Aoc2023Day20.php @@ -83,7 +83,7 @@ public static function fromString(string $s): static if (count($a) != 2) { throw new \Exception('Invalid input'); } - // @phpstan-ignore-next-line + // @phpstan-ignore new.static $m = new static(); $m->name = $a[0]; $m->outputs = explode(', ', $a[1]); diff --git a/src/Aoc2023/Aoc2023Day21.php b/src/Aoc2023/Aoc2023Day21.php index c68c0ea..c32edeb 100644 --- a/src/Aoc2023/Aoc2023Day21.php +++ b/src/Aoc2023/Aoc2023Day21.php @@ -178,12 +178,12 @@ private function solvePart1(int $fromX, int $fromY, int $maxStep): int $visited[$hash] = true; } } - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo "---- grid: [{$this->maxX} x {$this->maxY}]: from ({$fromX}, {$fromY}), steps: {$maxStep}, result = " . count($result), PHP_EOL; - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DETAILED_DEBUG) { $resultGrid = $this->grid; foreach (array_keys($result) as $hash) { diff --git a/src/Aoc2023/Aoc2023Day24.php b/src/Aoc2023/Aoc2023Day24.php index 48e1f26..62c4130 100644 --- a/src/Aoc2023/Aoc2023Day24.php +++ b/src/Aoc2023/Aoc2023Day24.php @@ -158,7 +158,7 @@ public function solve(array $input): array } if ($isOk) { $ans2 = intval(array_sum($rock->p)); - // @phpstan-ignore-next-line + // @phpstan-ignore if.alwaysFalse if (self::DEBUG) { // @codeCoverageIgnoreStart echo '---- ' . $rock->toString(), PHP_EOL;