Skip to content

Commit 6b3448e

Browse files
committed
Improve ChangeStreamIterator handling of wrapped iterator
1 parent 8ee9459 commit 6b3448e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/ChangeStream.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace MongoDB;
1919

2020
use Iterator;
21-
use MongoDB\Driver\Cursor;
2221
use MongoDB\Driver\CursorId;
2322
use MongoDB\Driver\Exception\ConnectionException;
2423
use MongoDB\Driver\Exception\RuntimeException;
@@ -29,7 +28,6 @@
2928
use MongoDB\Model\ChangeStreamIterator;
3029
use ReturnTypeWillChange;
3130

32-
use function assert;
3331
use function call_user_func;
3432
use function in_array;
3533

@@ -116,10 +114,7 @@ public function current()
116114
*/
117115
public function getCursorId()
118116
{
119-
$cursor = $this->iterator->getInnerIterator();
120-
assert($cursor instanceof Cursor);
121-
122-
return $cursor->getId();
117+
return $this->iterator->getInnerIterator()->getId();
123118
}
124119

125120
/**

src/Model/ChangeStreamIterator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use MongoDB\Exception\UnexpectedValueException;
3131
use ReturnTypeWillChange;
3232

33+
use function assert;
3334
use function count;
3435
use function is_array;
3536
use function is_object;
@@ -44,7 +45,6 @@
4445
* rewind() do not execute getMore commands.
4546
*
4647
* @internal
47-
* @method Cursor getInnerIterator()
4848
*/
4949
class ChangeStreamIterator extends IteratorIterator implements CommandSubscriber
5050
{
@@ -135,6 +135,14 @@ public function current()
135135
return $this->isValid ? parent::current() : null;
136136
}
137137

138+
final public function getInnerIterator(): Cursor
139+
{
140+
$cursor = parent::getInnerIterator();
141+
assert($cursor instanceof Cursor);
142+
143+
return $cursor;
144+
}
145+
138146
/**
139147
* Returns the resume token for the iterator's current position.
140148
*

0 commit comments

Comments
 (0)