Skip to content

Commit

Permalink
bumped to phpstan 1.11
Browse files Browse the repository at this point in the history
  • Loading branch information
tbali0524 committed May 13, 2024
1 parent a65bea1 commit bbd0cbe
Show file tree
Hide file tree
Showing 48 changed files with 91 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<!--
phpcs configuration file.
minimum version: ^3.8
minimum version: ^3.9
@see https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
-->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="advent-of-code-solutions">
<description>PHP_CodeSniffer configuration</description>
<config name="php_version" value="80200"/>
<config name="php_version" value="80300"/>
<arg name="cache" value=".tools/.phpcs.cache"/>
<arg name="extensions" value="php"/>
<arg name="encoding" value="utf-8"/>
Expand Down
7 changes: 4 additions & 3 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PHPStan configuration file.
#
# minimum version: ^1.10.57
# minimum version: ^1.11
#
# @see https://phpstan.org/config-reference
parameters:
Expand All @@ -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
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<!--
PHPUnit configuration file.
minimum version: ^11.0
minimum version: ^11.1
@see https://phpunit.readthedocs.io/en/11.0/configuration.html
-->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".tools/.phpunit.cache/"
colors="true"
Expand Down
3 changes: 0 additions & 3 deletions src/Aoc/AocRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function run(): void
echo '======= ' . $year . ' ' . str_repeat('=', 45) . PHP_EOL;
$lastYear = $year;
}
// @ phpstan-ignore-next-line
if (isset(self::TO_SKIP[$year]) and in_array($day, self::TO_SKIP[$year])) {
echo '=== AoC ' . $year . ' Day ' . str_pad(strval($day), 2, '0', STR_PAD_LEFT) . PHP_EOL;
echo Tags::WARN_TAG . 'Skipped.' . PHP_EOL;
Expand All @@ -153,11 +152,9 @@ public function run(): void
if ($countFails > 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 {
Expand Down
6 changes: 3 additions & 3 deletions src/Aoc2015/Aoc2015Day12.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aoc2016/Aoc2016Day08.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/Aoc2017/Aoc2017Day18.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aoc2017/Aoc2017Day20.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Aoc2017/Aoc2017Day21.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Aoc2018/Aoc2018Day09.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Aoc2018/Aoc2018Day10.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Aoc2018/Aoc2018Day15.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 '
Expand Down
4 changes: 2 additions & 2 deletions src/Aoc2018/Aoc2018Day16.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Aoc2018/Aoc2018Day17.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/Aoc2018/Aoc2018Day19.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -87,23 +87,23 @@ 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;
}
}
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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Aoc2018/Aoc2018Day21.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Aoc2018/Aoc2018Day23.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Aoc2018/Aoc2018Day24.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Aoc2019/Aoc2019Day11.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
4 changes: 2 additions & 2 deletions src/Aoc2019/Aoc2019Day13.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit bbd0cbe

Please sign in to comment.