Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ArrayIterator;
use ArrayLookup\Assert\Filter;
use ArrayObject;
use SplFixedArray;
use Traversable;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -51,6 +52,10 @@ private static function resolveArrayFromTraversable(Traversable $traversable): a
return $traversable->getArrayCopy();
}

if ($traversable instanceof SplFixedArray) {
return $traversable->toArray();
}

return iterator_to_array($traversable);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use SplFixedArray;
use stdClass;

use function current;
Expand Down Expand Up @@ -248,6 +249,16 @@ public static function lastReturnKeyDataProvider(): Iterator
static fn(string $datum, int $key): bool => str_contains($datum, 'test') && $key === 1,
null,
];
yield [
SplFixedArray::fromArray([6, 7, 8, 9]),
static fn($datum): bool => $datum > 5,
3,
];
yield [
SplFixedArray::fromArray([6, 7, 8, 9]),
static fn($datum): bool => $datum < 5,
null,
];
}

/**
Expand Down
Loading