From 7fce581f1912302856125f54a74b7aebb1a5c939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Tue, 20 Aug 2024 15:32:48 +0200 Subject: [PATCH] qa: patch psalm issues which came up after upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/Array_.php | 8 ++++++-- src/Map.php | 6 +++--- src/OrderedList.php | 2 +- tests/GenericOrderedListTest.php | 5 +---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Array_.php b/src/Array_.php index 3e9920b..96d1bb9 100644 --- a/src/Array_.php +++ b/src/Array_.php @@ -53,7 +53,9 @@ public function first() throw new OutOfBoundsException('There are no values available.'); } - return reset($this->data); + $data = $this->data; + + return reset($data); } public function last() @@ -62,7 +64,9 @@ public function last() throw new OutOfBoundsException('There are no values available.'); } - return end($this->data); + $data = $this->data; + + return end($data); } public function isEmpty(): bool diff --git a/src/Map.php b/src/Map.php index dce1ebe..d824b59 100644 --- a/src/Map.php +++ b/src/Map.php @@ -201,7 +201,7 @@ public function intersect(MapInterface $other, callable|null $valueComparator = */ private function intersection(MapInterface $other, callable|null $valueComparator, callable|null $keyComparator): array { - if ($valueComparator && $keyComparator) { + if ($valueComparator !== null && $keyComparator !== null) { /** * @psalm-var array $intersection * @psalm-suppress ImpureFunctionCall Upstream projects have to ensure that they do not manipulate the @@ -217,7 +217,7 @@ private function intersection(MapInterface $other, callable|null $valueComparato return $intersection; } - if ($keyComparator) { + if ($keyComparator !== null) { /** * @psalm-var array $intersection * @psalm-suppress ImpureFunctionCall Upstream projects have to ensure that they do not manipulate the @@ -228,7 +228,7 @@ private function intersection(MapInterface $other, callable|null $valueComparato return $intersection; } - if (! $valueComparator) { + if ($valueComparator === null) { $valueComparator = $this->valueComparator(); } diff --git a/src/OrderedList.php b/src/OrderedList.php index 5ee5737..3fe4ba3 100644 --- a/src/OrderedList.php +++ b/src/OrderedList.php @@ -240,7 +240,7 @@ public function unify( try { $unique = $unified->get($identifier); - if ($callback) { + if ($callback !== null) { /** * @psalm-suppress ImpureFunctionCall Upstream projects have to ensure that they do not manipulate the * value here. diff --git a/tests/GenericOrderedListTest.php b/tests/GenericOrderedListTest.php index 56bb9ab..56aa1bc 100644 --- a/tests/GenericOrderedListTest.php +++ b/tests/GenericOrderedListTest.php @@ -21,10 +21,8 @@ use function array_fill; use function array_map; use function array_reverse; -use function assert; use function chr; use function in_array; -use function is_int; use function json_encode; use function md5; use function mt_rand; @@ -562,7 +560,6 @@ public function testCallbackOnDeduplicationIsOnlyCalledForDuplicates(): void $list->unify(null, function (int $duplicate, int $number) use (&$callbackCalled): int { self::assertEquals($duplicate, $number); - assert(is_int($callbackCalled)); $callbackCalled++; return $number; @@ -1250,6 +1247,7 @@ public function testForAllIsExecutedForAllEntries(): void ]); $callable = new CallableObject(['bar', 0], ['baz', 1], ['ooq', 2]); + /** @psalm-suppress PossiblyInvalidArgument */ $list->forAll($callable)->execute(); } @@ -1410,7 +1408,6 @@ public function testWillFindIndexOfFirstMatchingItem(): void 1000, ]); - /** @psalm-suppress TypeDoesNotContainType Might be a psalm bug */ self::assertSame(1, $list->findFirstMatchingIndex(fn (int $value) => $value % 10 === 0)); }