12
12
final class Result implements IteratorAggregate, Countable
13
13
{
14
14
/**
15
- * @var Traversable
15
+ * @var Iterator
16
16
*/
17
17
private $ iterator ;
18
18
@@ -21,7 +21,7 @@ final class Result implements IteratorAggregate, Countable
21
21
*/
22
22
private $ count ;
23
23
24
- public function __construct (Traversable $ items , int $ count )
24
+ public function __construct (Iterator $ items , int $ count )
25
25
{
26
26
$ this ->iterator = $ items ;
27
27
$ this ->count = $ count ;
@@ -33,8 +33,8 @@ public static function fromIterable(iterable $items): self
33
33
return self ::fromArray ($ items );
34
34
}
35
35
36
- if ($ items instanceof Traversable ) {
37
- return self ::fromTraversable ($ items );
36
+ if ($ items instanceof Iterator ) {
37
+ return self ::fromIterator ($ items );
38
38
}
39
39
40
40
throw new InvalidArgumentException ('Items should be array or Traversable ' );
@@ -48,13 +48,13 @@ public static function fromArray(array $items): self
48
48
);
49
49
}
50
50
51
- public static function fromTraversable ( Traversable $ items ): self
51
+ public static function fromIterator ( Iterator $ items ): self
52
52
{
53
53
$ count = self ::countItems ($ items );
54
54
return new self ($ items , $ count );
55
55
}
56
56
57
- public function getIterator (): Traversable
57
+ public function getIterator (): Iterator
58
58
{
59
59
return $ this ->iterator ;
60
60
}
@@ -64,7 +64,7 @@ public function count(): int
64
64
return $ this ->count ;
65
65
}
66
66
67
- private static function countItems (Traversable $ items ): int
67
+ private static function countItems (Iterator $ items ): int
68
68
{
69
69
if ($ items instanceof Countable) {
70
70
$ count = $ items ->count ();
@@ -73,9 +73,7 @@ private static function countItems(Traversable $items): int
73
73
foreach ($ items as $ v ) {
74
74
++$ count ;
75
75
}
76
- if ($ items instanceof Iterator) {
77
- $ items ->rewind ();
78
- }
76
+ $ items ->rewind ();
79
77
}
80
78
81
79
return $ count ;
0 commit comments