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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Collections library for php language",
"minimum-stability": "dev",
"license": "MIT",
"version": "1.1.3",
"version": "1.1.4",
"authors": [
{
"name": "Maxim Sokolovsky",
Expand Down
13 changes: 8 additions & 5 deletions src/WS/Utils/Collections/CollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public static function fromStrict(array $values): Collection
*/
public static function fromIterable(iterable $iterable): Collection
{
if ($iterable instanceof IteratorAggregate) {
/** @noinspection PhpUnhandledExceptionInspection */
$iterable = $iterable->getIterator();
}
if (self::isStatePatternIterator($iterable)) {
if ($iterable instanceof IteratorAggregate) {
/** @noinspection PhpUnhandledExceptionInspection */
$iterable = $iterable->getIterator();
}
if (!$iterable instanceof Iterator) {
throw new UnsupportedException('Only Iterator interface can be applied to IteratorCollection');
}
Expand All @@ -104,13 +104,16 @@ private static function isStatePatternIterator(iterable $iterable): bool
if (!is_object($iterable)) {
return false;
}
if (!method_exists($iterable, 'rewind')) {
return false;
}
$i = 2;
$lastItem = null;
foreach ($iterable as $item) {
if ($i === 0) {
break;
}
if (is_object($item) && $item === $lastItem && method_exists($item, 'rewind')) {
if (is_object($item) && $item === $lastItem) {
return true;
}
$lastItem = $item;
Expand Down