Skip to content

Commit

Permalink
fix: remove all array_is_list() checks (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi authored Jun 22, 2024
1 parent 57434df commit 05d7b28
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 0.12.1

* fix: remove all `array_is_list()` checks

# 0.12.0

* fix(`PagerItem`): `withPageNumber` should return static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getOffsetItems(int $offset, int $limit): array
// workaround: use indexBy
$items = $this->collection->matching($criteria)->toArray();

if ($this->indexBy !== null && array_is_list($items)) {
if ($this->indexBy !== null) {
$newItems = [];

/** @var T $item */
Expand Down Expand Up @@ -296,7 +296,7 @@ public function getKeysetItems(
// workaround: use indexBy
$items = $this->collection->matching($criteria)->toArray();

if ($this->indexBy !== null && array_is_list($items)) {
if ($this->indexBy !== null) {
$newItems = [];

/** @var T $item */
Expand Down
28 changes: 0 additions & 28 deletions packages/rekapager-keyset-pagination/src/Internal/KeysetPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ final class KeysetPage implements PageInterface, \IteratorAggregate

private ?bool $hasPreviousPage = null;
private ?bool $hasNextPage = null;
private ?bool $resultIsList = null;

/**
* @param KeysetPageable<TKey,T> $pageable
Expand Down Expand Up @@ -157,29 +156,6 @@ private function getRealResult(): array
$this->hasNextPage = false;
}

// determine if the result is a list

$this->resultIsList = true;
/** @var null|int */
$lastKey = null;
foreach ($result as $_ => $item) {
$key = $item->getKey();

if ($lastKey !== null) {
if (!\is_int($key) || !\is_int($lastKey)) {
$this->resultIsList = false;
break;
}

if ($key !== $lastKey + 1) {
$this->resultIsList = false;
break;
}
}

$lastKey = $key;
}

return $result;
}

Expand Down Expand Up @@ -421,10 +397,6 @@ public function getIterator(): \Traversable
$results[$result->getKey()] = $result->getValue();
}

if ($this->resultIsList) {
$results = array_values($results);
}

/** @psalm-suppress InvalidReturnStatement */
return new \ArrayIterator($results);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getOffsetItems(int $offset, int $limit): array
/** @psalm-suppress InvalidArgument */
$items = iterator_to_array($this->pagerfanta->getSlice($offset, $limit));

if ($this->indexBy !== null && array_is_list($items)) {
if ($this->indexBy !== null) {
$newItems = [];

/** @var T $item */
Expand Down

0 comments on commit 05d7b28

Please sign in to comment.