Skip to content

Commit 60a0af2

Browse files
committed
Fix. Iterator must have rewind method to used as state pattern.
1 parent c9b355f commit 60a0af2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Collections library for php language",
44
"minimum-stability": "dev",
55
"license": "MIT",
6-
"version": "1.1.2",
6+
"version": "1.1.3",
77
"authors": [
88
{
99
"name": "Maxim Sokolovsky",

src/WS/Utils/Collections/CollectionFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,16 @@ public static function empty(): Collection
101101

102102
private static function isStatePatternIterator(iterable $iterable): bool
103103
{
104+
if (!is_object($iterable)) {
105+
return false;
106+
}
104107
$i = 2;
105108
$lastItem = null;
106109
foreach ($iterable as $item) {
107110
if ($i === 0) {
108111
break;
109112
}
110-
if (is_object($item) && $item === $lastItem) {
113+
if (is_object($item) && $item === $lastItem && method_exists($item, 'rewind')) {
111114
return true;
112115
}
113116
$lastItem = $item;

0 commit comments

Comments
 (0)