Skip to content

Commit dc6ab3b

Browse files
committed
Specify callable explicitly in ChangeStream
1 parent 6b3448e commit dc6ab3b

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="4.x-dev@5108834088c1d8cae3698df6ef6bf15fe6e76c53">
3-
<file src="src/ChangeStream.php">
4-
<MixedAssignment occurrences="1">
5-
<code>$this-&gt;iterator</code>
6-
</MixedAssignment>
7-
</file>
83
<file src="src/Client.php">
94
<MixedArgument occurrences="1">
105
<code>$driverOptions['driver'] ?? []</code>
@@ -747,14 +742,8 @@
747742
<DocblockTypeContradiction occurrences="1">
748743
<code>isset($resumeToken) &amp;&amp; ! is_array($resumeToken) &amp;&amp; ! is_object($resumeToken)</code>
749744
</DocblockTypeContradiction>
750-
<MissingClosureParamType occurrences="2">
751-
<code>$hasAdvanced</code>
752-
<code>$resumeToken</code>
753-
</MissingClosureParamType>
754-
<MixedArgument occurrences="3">
755-
<code>$hasAdvanced</code>
745+
<MixedArgument occurrences="1">
756746
<code>$reply-&gt;cursor-&gt;firstBatch</code>
757-
<code>$resumeToken</code>
758747
</MixedArgument>
759748
<MixedAssignment occurrences="1">
760749
<code>$this-&gt;postBatchResumeToken</code>

src/ChangeStream.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use MongoDB\Driver\Exception\ServerException;
2525
use MongoDB\Exception\BadMethodCallException;
2626
use MongoDB\Exception\ResumeTokenException;
27-
use MongoDB\Exception\UnexpectedValueException;
2827
use MongoDB\Model\ChangeStreamIterator;
2928
use ReturnTypeWillChange;
3029

@@ -34,6 +33,8 @@
3433
/**
3534
* Iterator for a change stream.
3635
*
36+
* @psalm-type ResumeCallable = callable(array|object|null, bool): ChangeStreamIterator
37+
*
3738
* @api
3839
* @see \MongoDB\Collection::watch()
3940
* @see https://mongodb.com/docs/manual/reference/method/db.watch/#mongodb-method-db.watch
@@ -73,7 +74,7 @@ class ChangeStream implements Iterator
7374
/** @var int */
7475
private static $wireVersionForResumableChangeStreamError = 9;
7576

76-
/** @var callable|null */
77+
/** @var ResumeCallable|null */
7778
private $resumeCallable;
7879

7980
/** @var ChangeStreamIterator */
@@ -92,6 +93,8 @@ class ChangeStream implements Iterator
9293

9394
/**
9495
* @internal
96+
*
97+
* @param ResumeCallable $resumeCallable
9598
*/
9699
public function __construct(ChangeStreamIterator $iterator, callable $resumeCallable)
97100
{
@@ -257,9 +260,6 @@ private function resume(): void
257260
}
258261

259262
$this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken(), $this->hasAdvanced);
260-
if (! $this->iterator instanceof ChangeStreamIterator) {
261-
throw new UnexpectedValueException('Expected change stream iterator from callable');
262-
}
263263

264264
$this->iterator->rewind();
265265

src/Operation/Watch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public function execute(Server $server)
326326
{
327327
return new ChangeStream(
328328
$this->createChangeStreamIterator($server),
329-
function ($resumeToken, $hasAdvanced) {
329+
function ($resumeToken, $hasAdvanced): ChangeStreamIterator {
330330
return $this->resume($resumeToken, $hasAdvanced);
331331
}
332332
);

0 commit comments

Comments
 (0)