diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml
index 7b30232..abb3c0c 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.10, php-cs-fixer:3.61, phpstan:1.11
+ tools: phpcs:3.10, php-cs-fixer:3.64, phpstan:1.12
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php
index 8b50137..1c3c7de 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.61
+ * minimum version: ^3.64
*
* @see https://cs.symfony.com/doc/config.html
*/
@@ -21,10 +21,11 @@
return (new PhpCsFixer\Config())
->setRules([
- '@PHP83Migration' => true,
+ '@PHP84Migration' => true,
'@PHP80Migration:risky' => true, // this also needs: ->setRiskyAllowed(true)
'@PhpCsFixer' => true, // includes @Symfony, @PER-CS2.0, @PSR12, @PSR2, @PSR1
'@PhpCsFixer:risky' => true, // includes @Symfony:risky, @PER-CS2.0:risky, @PSR12:risky
+ '@PHPUnit100Migration:risky'=> true,
// override some @Symfony rules
'blank_line_before_statement' => false,
@@ -43,13 +44,11 @@
'native_function_invocation' => false,
'no_trailing_whitespace_in_string' => false,
'psr_autoloading' => false,
- 'self_accessor' => false,
'string_length_to_empty' => false,
// override some @PhpCsFixer:risky rules
'comment_to_phpdoc' => false,
'strict_comparison' => false,
- 'strict_param' => false,
])
->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.tools/.php-cs-fixer.cache')
diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml
index 663881a..4542bda 100644
--- a/phpdoc.dist.xml
+++ b/phpdoc.dist.xml
@@ -12,7 +12,7 @@ minimum version: ^3.5
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.phpdoc.org https://docs.phpdoc.org/latest/phpdoc.xsd"
>
-
Advent of Code solutions by TBali
+ Advent of Code solutions in PHP by TBali
.tools/phpdoc/cache
diff --git a/phpstan.dist.neon b/phpstan.dist.neon
index 33d8dd5..2cd3c37 100644
--- a/phpstan.dist.neon
+++ b/phpstan.dist.neon
@@ -1,6 +1,6 @@
# PHPStan configuration file.
#
-# minimum version: ^1.11
+# minimum version: ^1.12
#
# @see https://phpstan.org/config-reference
parameters:
@@ -17,7 +17,7 @@ parameters:
- vendor
ignoreErrors:
-
- message: '#^(Static )?[Mm]ethod 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 701cc79..4d2804a 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -4,7 +4,7 @@ PHPUnit configuration file.
minimum version: ^11.3
-@see https://phpunit.readthedocs.io/en/11.0/configuration.html
+@see https://phpunit.readthedocs.io/en/11.3/configuration.html
-->
processArgs($args);
$this->isOk = true;
}
@@ -128,7 +128,7 @@ public function run(): void
echo '======= ' . $year . ' ' . str_repeat('=', 45) . PHP_EOL;
$lastYear = $year;
}
- if (in_array($day, self::TO_SKIP[$year])) {
+ if (in_array($day, self::TO_SKIP[$year], true)) {
echo '=== AoC ' . $year . ' Day ' . str_pad(strval($day), 2, '0', STR_PAD_LEFT) . PHP_EOL;
echo Tags::WARN_TAG . 'Skipped.' . PHP_EOL;
++$countSkipped;
diff --git a/src/Aoc2015/Aoc2015Day21.php b/src/Aoc2015/Aoc2015Day21.php
index 75638a3..1e226af 100644
--- a/src/Aoc2015/Aoc2015Day21.php
+++ b/src/Aoc2015/Aoc2015Day21.php
@@ -109,7 +109,7 @@ public function __construct(
) {
}
- public function canWin(Character $enemy): bool
+ public function canWin(self $enemy): bool
{
$turnsToWin = intval(ceil($enemy->hp / max(1, $this->damage - $enemy->armor)));
$turnsToLoose = intval(ceil($this->hp / max(1, $enemy->damage - $this->armor)));
diff --git a/src/Aoc2017/Aoc2017Day17.php b/src/Aoc2017/Aoc2017Day17.php
index 35998ab..209a6b1 100644
--- a/src/Aoc2017/Aoc2017Day17.php
+++ b/src/Aoc2017/Aoc2017Day17.php
@@ -84,7 +84,7 @@ public function __construct(
/**
* Get the item off by $delta positions.
*/
- public function nth(int $delta): ListItem
+ public function nth(int $delta): self
{
$ans = $this;
while ($delta > 0) {
diff --git a/src/Aoc2018/Aoc2018Day09.php b/src/Aoc2018/Aoc2018Day09.php
index 4b09300..e3ace60 100644
--- a/src/Aoc2018/Aoc2018Day09.php
+++ b/src/Aoc2018/Aoc2018Day09.php
@@ -98,7 +98,7 @@ public function removeLeft(): int
/**
* Get the item off by $delta positions (left or right).
*/
- public function nth(int $delta): ListItem
+ public function nth(int $delta): self
{
$ans = $this;
if ($delta >= 0) {
@@ -120,7 +120,7 @@ public function nth(int $delta): ListItem
public static function init(): self
{
- $item = new ListItem(0);
+ $item = new self(0);
$item->prev = $item;
$item->next = $item;
return $item;
diff --git a/src/Aoc2019/Aoc2019Day12.php b/src/Aoc2019/Aoc2019Day12.php
index 4d749d2..85e8787 100644
--- a/src/Aoc2019/Aoc2019Day12.php
+++ b/src/Aoc2019/Aoc2019Day12.php
@@ -135,7 +135,7 @@ public function toString(): string
. '>' . PHP_EOL;
}
- public function gravity(Moon $moon): void
+ public function gravity(self $moon): void
{
$this->vx += ($moon->x <=> $this->x);
$this->vy += ($moon->y <=> $this->y);
diff --git a/src/Aoc2019/Aoc2019Day15.php b/src/Aoc2019/Aoc2019Day15.php
index 77411d6..1249575 100644
--- a/src/Aoc2019/Aoc2019Day15.php
+++ b/src/Aoc2019/Aoc2019Day15.php
@@ -225,7 +225,7 @@ public function printMap(int $droidX, int $droidY): void
if (($x == 0) and ($y == 0)) {
$s .= '0';
} elseif (($x == $droidX) and ($y == $droidY)) {
- $s .= Map::DROID;
+ $s .= self::DROID;
} else {
$s .= $this->grid[$y][$x] ?? self::UNKNOWN;
}
diff --git a/src/Aoc2019/Aoc2019Day22.php b/src/Aoc2019/Aoc2019Day22.php
index 4a06803..ebf1d67 100644
--- a/src/Aoc2019/Aoc2019Day22.php
+++ b/src/Aoc2019/Aoc2019Day22.php
@@ -272,7 +272,7 @@ final public function __construct(
) {
}
- public function compose(LCF $inner): static
+ public function compose(self $inner): static
{
if ($this->modulus != $inner->modulus) {
// @codeCoverageIgnoreStart
diff --git a/src/Aoc2020/Aoc2020Day04.php b/src/Aoc2020/Aoc2020Day04.php
index 1a0accc..1260ae7 100644
--- a/src/Aoc2020/Aoc2020Day04.php
+++ b/src/Aoc2020/Aoc2020Day04.php
@@ -60,7 +60,7 @@ public function solve(array $input): array
default => false
},
'hcl' => strlen($v) == 7 && $v[0] == '#' && ctype_xdigit(substr($v, 1)),
- 'ecl' => in_array($v, ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth']),
+ 'ecl' => in_array($v, ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth'], true),
'pid' => strlen($v) == 9 && ctype_digit($v),
'cid' => true,
// @codeCoverageIgnoreStart
diff --git a/src/Aoc2020/Aoc2020Day07.php b/src/Aoc2020/Aoc2020Day07.php
index 327dd5d..7dec07b 100644
--- a/src/Aoc2020/Aoc2020Day07.php
+++ b/src/Aoc2020/Aoc2020Day07.php
@@ -76,7 +76,7 @@ public function __construct(array $input = [])
throw new \Exception('Invalid input');
}
for ($i = 1; $i < intdiv(count($a), 4); ++$i) {
- if (!is_numeric($a[4 * $i]) or !in_array($a[4 * $i + 3], ['bag,', 'bags,', 'bag.', 'bags.'])) {
+ if (!is_numeric($a[4 * $i]) or !in_array($a[4 * $i + 3], ['bag,', 'bags,', 'bag.', 'bags.'], true)) {
throw new \Exception('Invalid input');
}
$innerBag = $a[4 * $i + 1] . ' ' . $a[4 * $i + 2];
diff --git a/src/Aoc2020/Aoc2020Day08.php b/src/Aoc2020/Aoc2020Day08.php
index fa53277..706c6bc 100644
--- a/src/Aoc2020/Aoc2020Day08.php
+++ b/src/Aoc2020/Aoc2020Day08.php
@@ -46,10 +46,10 @@ public function solve(array $input): array
$ans2 = 0;
for ($i = 0; $i < count($input); ++$i) {
$instruction = substr($input[$i], 0, 3);
- if (!in_array($instruction, ['jmp', 'nop'])) {
+ if (!in_array($instruction, ['jmp', 'nop'], true)) {
continue;
}
- $modInstruction = ['jmp' => 'nop', 'nop' => 'jmp'][$instruction] ?? 'err';
+ $modInstruction = ['jmp' => 'nop', 'nop' => 'jmp'][$instruction];
$modInput = $input;
$modInput[$i] = $modInstruction . substr($input[$i], 3);
[$wasInfLoop, $ans2] = $this->execute($modInput);
diff --git a/src/Aoc2020/Aoc2020Day18.php b/src/Aoc2020/Aoc2020Day18.php
index 5aa5351..442ab7e 100644
--- a/src/Aoc2020/Aoc2020Day18.php
+++ b/src/Aoc2020/Aoc2020Day18.php
@@ -97,7 +97,7 @@ public function evaluate(): int
if ($this->expr[$start] == '(') {
$end = $this->getCloseParPos($start);
$parString = substr($this->expr, $start + 1, $end - $start - 1);
- $parExpression = new Expression($parString, $this->precedences);
+ $parExpression = new self($parString, $this->precedences);
$this->operands[] = $parExpression->evaluate();
++$end;
} elseif (ctype_digit($this->expr[$start])) {
diff --git a/src/Aoc2020/Aoc2020Day19.php b/src/Aoc2020/Aoc2020Day19.php
index bbaad4a..27fbba0 100644
--- a/src/Aoc2020/Aoc2020Day19.php
+++ b/src/Aoc2020/Aoc2020Day19.php
@@ -51,7 +51,7 @@ public function solve(array $input): array
$allStrings = array_keys($this->getAllGenerated(0, $maxLen));
$ans1 = count(array_filter(
$this->messages,
- static fn (string $x): bool => in_array($x, $allStrings),
+ static fn (string $x): bool => in_array($x, $allStrings, true),
));
// ---------- Part 2
// detect puzzle example #1, valid for Part 1 only
diff --git a/src/Aoc2020/Aoc2020Day20.php b/src/Aoc2020/Aoc2020Day20.php
index 9834df0..1c8ba1f 100644
--- a/src/Aoc2020/Aoc2020Day20.php
+++ b/src/Aoc2020/Aoc2020Day20.php
@@ -673,11 +673,11 @@ public static function fromGridTile(array $gridTile, array $gridPos): self
return $img;
}
- public function findMonsters(Image $monsterImage): int
+ public function findMonsters(self $monsterImage): int
{
$needle = new SearchPattern($monsterImage);
$best = 0;
- $bestImg = new Image(0, 0);
+ $bestImg = new self(0, 0);
for ($pos = 0; $pos < 16; ++$pos) {
$haystack = self::fromStrings(ImageTile::orientImage($this->grid, $pos));
$result = $haystack->findIfOriented($needle);
diff --git a/src/Aoc2020/Aoc2020Day21.php b/src/Aoc2020/Aoc2020Day21.php
index a7df736..e357e5a 100644
--- a/src/Aoc2020/Aoc2020Day21.php
+++ b/src/Aoc2020/Aoc2020Day21.php
@@ -120,8 +120,8 @@ public function solve(array $input): array
// @codeCoverageIgnoreEnd
}
$idIngred = array_key_first($this->canComeFrom[$idBestAllerg]);
- $nameIngred = array_search($idIngred, $this->ingredients);
- $nameAllerg = array_search($idBestAllerg, $this->allergens);
+ $nameIngred = array_search($idIngred, $this->ingredients, true);
+ $nameAllerg = array_search($idBestAllerg, $this->allergens, true);
if (($nameIngred === false) or ($nameAllerg === false)) {
// @codeCoverageIgnoreStart
throw new \Exception('No solution found');
diff --git a/src/Aoc2021/Aoc2021Day08.php b/src/Aoc2021/Aoc2021Day08.php
index 0d4f74f..c616b12 100644
--- a/src/Aoc2021/Aoc2021Day08.php
+++ b/src/Aoc2021/Aoc2021Day08.php
@@ -72,7 +72,7 @@ public function solve(array $input): array
$ans1 = 0;
foreach ($outputs as $patterns) {
foreach ($patterns as $pattern) {
- if (in_array(strlen($pattern), [2, 3, 4, 7])) {
+ if (in_array(strlen($pattern), [2, 3, 4, 7], true)) {
++$ans1;
}
}
@@ -84,12 +84,12 @@ public function solve(array $input): array
$segments[0] = current(array_diff($patterns[1], $patterns[0]));
$freq = array_count_values(array_merge(...$patterns));
// # of times a given segment is used in all digits: 8, 6, 8, 7, 4, 9, 7
- $segments[2] = current(array_diff(array_keys($freq, 8), [$segments[0]]));
- $segments[1] = current(array_keys($freq, 6));
- $segments[4] = current(array_keys($freq, 4));
- $segments[5] = current(array_keys($freq, 9));
+ $segments[2] = current(array_diff(array_keys($freq, 8, true), [$segments[0]]));
+ $segments[1] = current(array_keys($freq, 6, true));
+ $segments[4] = current(array_keys($freq, 4, true));
+ $segments[5] = current(array_keys($freq, 9, true));
$segments[3] = current(array_diff(array_diff($patterns[2], $patterns[0]), [$segments[1]]));
- $segments[6] = current(array_diff(array_keys($freq, 7), [$segments[3]]));
+ $segments[6] = current(array_diff(array_keys($freq, 7, true), [$segments[3]]));
$map = [];
for ($digit = 0; $digit < 10; ++$digit) {
$digitSegments = [];
diff --git a/src/Aoc2021/Aoc2021Day18.php b/src/Aoc2021/Aoc2021Day18.php
index 6e98d78..3aa73bd 100644
--- a/src/Aoc2021/Aoc2021Day18.php
+++ b/src/Aoc2021/Aoc2021Day18.php
@@ -347,26 +347,26 @@ public static function add(self $a, self $b): self
*/
private function unitTest(): void
{
- assert(Snailfish::fromString('[[[[[9,8],1],2],3],4]')->reduce()->toString() === '[[[[0,9],2],3],4]');
- assert(Snailfish::fromString('[7,[6,[5,[4,[3,2]]]]]')->reduce()->toString() === '[7,[6,[5,[7,0]]]]');
- assert(Snailfish::fromString('[[6,[5,[4,[3,2]]]],1]')->reduce()->toString() === '[[6,[5,[7,0]]],3]');
- assert(Snailfish::fromString('[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]]')->reduce()->toString()
+ assert(self::fromString('[[[[[9,8],1],2],3],4]')->reduce()->toString() === '[[[[0,9],2],3],4]');
+ assert(self::fromString('[7,[6,[5,[4,[3,2]]]]]')->reduce()->toString() === '[7,[6,[5,[7,0]]]]');
+ assert(self::fromString('[[6,[5,[4,[3,2]]]],1]')->reduce()->toString() === '[[6,[5,[7,0]]],3]');
+ assert(self::fromString('[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]]')->reduce()->toString()
=== '[[3,[2,[8,0]]],[9,[5,[7,0]]]]');
- assert(Snailfish::fromString('[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]]')->reduce()->toString()
+ assert(self::fromString('[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]]')->reduce()->toString()
=== '[[[[0,7],4],[[7,8],[6,0]]],[8,1]]');
- assert(Snailfish::fromString('[[9,1],[1,9]]')->magnitude() === 129);
- assert(Snailfish::fromString('[[[[0,7],4],[[7,8],[6,0]]],[8,1]]')->magnitude() === 1384);
- assert(Snailfish::fromString('[[[[1,1],[2,2]],[3,3]],[4,4]]')->magnitude() === 445);
- assert(Snailfish::fromString('[[[[3,0],[5,3]],[4,4]],[5,5]]')->magnitude() === 791);
- assert(Snailfish::fromString('[[[[5,0],[7,4]],[5,5]],[6,6]]')->magnitude() === 1137);
- assert(Snailfish::fromString('[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]')->magnitude() === 3488);
- assert(Snailfish::add(
- Snailfish::fromString('[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]'),
- Snailfish::fromString('[7,[[[3,7],[4,3]],[[6,3],[8,8]]]]'),
+ assert(self::fromString('[[9,1],[1,9]]')->magnitude() === 129);
+ assert(self::fromString('[[[[0,7],4],[[7,8],[6,0]]],[8,1]]')->magnitude() === 1384);
+ assert(self::fromString('[[[[1,1],[2,2]],[3,3]],[4,4]]')->magnitude() === 445);
+ assert(self::fromString('[[[[3,0],[5,3]],[4,4]],[5,5]]')->magnitude() === 791);
+ assert(self::fromString('[[[[5,0],[7,4]],[5,5]],[6,6]]')->magnitude() === 1137);
+ assert(self::fromString('[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]')->magnitude() === 3488);
+ assert(self::add(
+ self::fromString('[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]'),
+ self::fromString('[7,[[[3,7],[4,3]],[[6,3],[8,8]]]]'),
)->toString() === '[[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]');
- assert(Snailfish::add(
- Snailfish::fromString('[[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]'),
- Snailfish::fromString('[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]]'),
+ assert(self::add(
+ self::fromString('[[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]'),
+ self::fromString('[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]]'),
)->toString() === '[[[[6,7],[6,7]],[[7,7],[0,7]]],[[[8,7],[7,7]],[[8,8],[8,0]]]]');
}
}
diff --git a/src/Aoc2021/Aoc2021Day21.php b/src/Aoc2021/Aoc2021Day21.php
index 648d9d0..e0e282d 100644
--- a/src/Aoc2021/Aoc2021Day21.php
+++ b/src/Aoc2021/Aoc2021Day21.php
@@ -56,7 +56,7 @@ public function solve(array $input): array
$count = sscanf($input[$i] ?? '', 'Player %d starting position: %d', $player, $startPos);
/** @var int $player */
/** @var int $startPos */
- if (($count != 2) or !in_array($player, [1, 2]) or ($startPos < 1) or ($startPos > self::MAX_POS)) {
+ if (($count != 2) or !in_array($player, [1, 2], true) or ($startPos < 1) or ($startPos > self::MAX_POS)) {
throw new \Exception('Invalid input');
}
// transpose to 0-based player id and positions id.
diff --git a/src/Aoc2022/Aoc2022Day07.php b/src/Aoc2022/Aoc2022Day07.php
index 6398877..2c9c764 100644
--- a/src/Aoc2022/Aoc2022Day07.php
+++ b/src/Aoc2022/Aoc2022Day07.php
@@ -138,7 +138,7 @@ final class Directory
public bool $wasListed = false;
public int $totalSize = 0;
- public function __construct(string $name, ?Directory $parent = null)
+ public function __construct(string $name, ?self $parent = null)
{
$this->name = $name;
$this->parent = $parent;
diff --git a/src/Aoc2022/Aoc2022Day13.php b/src/Aoc2022/Aoc2022Day13.php
index 34b80a0..07a6257 100644
--- a/src/Aoc2022/Aoc2022Day13.php
+++ b/src/Aoc2022/Aoc2022Day13.php
@@ -149,7 +149,7 @@ public static function fromString(string $s): self
return $item;
}
- public static function compare(Item $a, Item $b): int
+ public static function compare(self $a, self $b): int
{
if (!$a->isList and !$b->isList) {
return $a->value <=> $b->value;
diff --git a/src/Aoc2022/Aoc2022Day15.php b/src/Aoc2022/Aoc2022Day15.php
index 29cf5d8..65ccd56 100644
--- a/src/Aoc2022/Aoc2022Day15.php
+++ b/src/Aoc2022/Aoc2022Day15.php
@@ -226,23 +226,23 @@ public static function fromSensor(Sensor $s): self
*
* @return array
*/
- public function diff(Rect $r): array
+ public function diff(self $r): array
{
if (($this->b1 < $r->b0) or ($r->b1 < $this->b0) or ($this->a1 < $r->a0) or ($r->a1 < $this->a0)) {
return [$this];
}
$ans = [];
if ($this->a0 < $r->a0) {
- $ans[] = new Rect($this->a0, $this->b0, $r->a0 - 1, $this->b1);
+ $ans[] = new self($this->a0, $this->b0, $r->a0 - 1, $this->b1);
}
if ($r->a1 < $this->a1) {
- $ans[] = new Rect($r->a1 + 1, $this->b0, $this->a1, $this->b1);
+ $ans[] = new self($r->a1 + 1, $this->b0, $this->a1, $this->b1);
}
if ($this->b0 < $r->b0) {
- $ans[] = new Rect(max($r->a0, $this->a0), $this->b0, min($r->a1, $this->a1), $r->b0 - 1);
+ $ans[] = new self(max($r->a0, $this->a0), $this->b0, min($r->a1, $this->a1), $r->b0 - 1);
}
if ($r->b1 < $this->b1) {
- $ans[] = new Rect(max($r->a0, $this->a0), $r->b1 + 1, min($r->a1, $this->a1), $this->b1);
+ $ans[] = new self(max($r->a0, $this->a0), $r->b1 + 1, min($r->a1, $this->a1), $this->b1);
}
return $ans;
}
diff --git a/src/Aoc2022/Aoc2022Day20.php b/src/Aoc2022/Aoc2022Day20.php
index e71dce5..5d952b2 100644
--- a/src/Aoc2022/Aoc2022Day20.php
+++ b/src/Aoc2022/Aoc2022Day20.php
@@ -133,7 +133,7 @@ public function __construct(
/**
* Get the item off by $delta positions (left or right).
*/
- public function nth(int $delta): ListItem
+ public function nth(int $delta): self
{
$ans = $this;
if ($delta >= 0) {
diff --git a/src/Aoc2023/Aoc2023Day02.php b/src/Aoc2023/Aoc2023Day02.php
index d36f1fc..9b5fae0 100644
--- a/src/Aoc2023/Aoc2023Day02.php
+++ b/src/Aoc2023/Aoc2023Day02.php
@@ -90,7 +90,7 @@ public function __construct(
) {
}
- public function isPossible(Hand $bag): bool
+ public function isPossible(self $bag): bool
{
return $this->red <= $bag->red && $this->green <= $bag->green && $this->blue <= $bag->blue;
}
diff --git a/src/Aoc2023/Aoc2023Day14.php b/src/Aoc2023/Aoc2023Day14.php
index aba76e2..90e5fd8 100644
--- a/src/Aoc2023/Aoc2023Day14.php
+++ b/src/Aoc2023/Aoc2023Day14.php
@@ -147,6 +147,7 @@ private function tiltWest(): void
while ($this->grid[$y][$newX] == 'O') {
++$newX;
}
+ // @phpstan-ignore assign.propertyType
$this->grid[$y][$newX] = 'O';
}
}
@@ -191,6 +192,7 @@ private function tiltEast(): void
while ($this->grid[$y][$newX] == 'O') {
--$newX;
}
+ // @phpstan-ignore assign.propertyType
$this->grid[$y][$newX] = 'O';
}
}
diff --git a/src/Aoc2023/Aoc2023Day18.php b/src/Aoc2023/Aoc2023Day18.php
index 6069d65..70f5553 100644
--- a/src/Aoc2023/Aoc2023Day18.php
+++ b/src/Aoc2023/Aoc2023Day18.php
@@ -47,6 +47,7 @@ public function solve(array $input): array
$directions = '';
$directionsPart2 = '';
$steps = [];
+ $stepsPart2 = [];
foreach ($input as $line) {
$a = explode(' ', $line);
if ((count($a) != 3) or !str_contains('URDL', $a[0]) or (strlen($a[2]) != 9)) {
diff --git a/src/Aoc2023/Aoc2023Day19.php b/src/Aoc2023/Aoc2023Day19.php
index c2ee332..deff031 100644
--- a/src/Aoc2023/Aoc2023Day19.php
+++ b/src/Aoc2023/Aoc2023Day19.php
@@ -179,7 +179,7 @@ public static function fromString(string $s): self
if ((count($a) != 2) or ($s[-1] != '}')) {
throw new \Exception('Invalid input');
}
- $w = new Workflow();
+ $w = new self();
$w->name = $a[0];
$rules = explode(',', substr($a[1], 0, -1));
foreach ($rules as $idx => $rule) {
@@ -220,7 +220,7 @@ public static function fromString(string $s): self
if ($count != 4) {
throw new \Exception('Invalid input');
}
- $p = new Part();
+ $p = new self();
$p->properties = ['x' => intval($vx), 'm' => intval($vm), 'a' => intval($va), 's' => intval($vs)];
return $p;
}
diff --git a/src/Aoc2023/Aoc2023Day20.php b/src/Aoc2023/Aoc2023Day20.php
index c7b83f3..94d59c1 100644
--- a/src/Aoc2023/Aoc2023Day20.php
+++ b/src/Aoc2023/Aoc2023Day20.php
@@ -208,7 +208,7 @@ public function simSteps(int $maxSteps): void
$turn = 0;
$pq = new MinPriorityQueueDay20();
$pq->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
- $pq->insert([Circuit::BUTTON, Circuit::BROADCASTER, Pulse::LOW], $turn);
+ $pq->insert([self::BUTTON, self::BROADCASTER, Pulse::LOW], $turn);
while (!$pq->isEmpty()) {
$item = $pq->extract();
/** @phpstan-var array{priority: int, data: array{string, string, Pulse}} $item */
@@ -263,7 +263,7 @@ public function minButtonsToRx(): int
$turn = 0;
$pq = new MinPriorityQueueDay20();
$pq->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
- $pq->insert([Circuit::BUTTON, Circuit::BROADCASTER, Pulse::LOW], $turn);
+ $pq->insert([self::BUTTON, self::BROADCASTER, Pulse::LOW], $turn);
while (!$pq->isEmpty()) {
$item = $pq->extract();
/** @phpstan-var array{priority: int, data: array{string, string, Pulse}} $item */
diff --git a/src/Aoc2023/Aoc2023Day22.php b/src/Aoc2023/Aoc2023Day22.php
index 5bf4817..7a31302 100644
--- a/src/Aoc2023/Aoc2023Day22.php
+++ b/src/Aoc2023/Aoc2023Day22.php
@@ -72,7 +72,7 @@ public static function fromString(string $s, int $id = 0): self
if ($count != 6) {
throw new \Exception('Invalid input');
}
- $b = new Brick($id);
+ $b = new self($id);
$b->from = [intval($x1), intval($y1), intval($z1)];
$b->to = [intval($x2), intval($y2), intval($z2)];
if (