Skip to content

Commit

Permalink
qa: patch psalm issues which came up after upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Bösing <[email protected]>
  • Loading branch information
boesing committed Aug 20, 2024
1 parent 9f62c92 commit 7fce581
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey,TValue> $intersection
* @psalm-suppress ImpureFunctionCall Upstream projects have to ensure that they do not manipulate the
Expand All @@ -217,7 +217,7 @@ private function intersection(MapInterface $other, callable|null $valueComparato
return $intersection;
}

if ($keyComparator) {
if ($keyComparator !== null) {
/**
* @psalm-var array<TKey,TValue> $intersection
* @psalm-suppress ImpureFunctionCall Upstream projects have to ensure that they do not manipulate the
Expand All @@ -228,7 +228,7 @@ private function intersection(MapInterface $other, callable|null $valueComparato
return $intersection;
}

if (! $valueComparator) {
if ($valueComparator === null) {
$valueComparator = $this->valueComparator();
}

Expand Down
2 changes: 1 addition & 1 deletion src/OrderedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions tests/GenericOrderedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1250,6 +1247,7 @@ public function testForAllIsExecutedForAllEntries(): void
]);

$callable = new CallableObject(['bar', 0], ['baz', 1], ['ooq', 2]);
/** @psalm-suppress PossiblyInvalidArgument */
$list->forAll($callable)->execute();
}

Expand Down Expand Up @@ -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));
}

Expand Down

0 comments on commit 7fce581

Please sign in to comment.