Skip to content

Commit 7a4b42c

Browse files
committed
Use decode() instead of decodeIfSupported()
1 parent c3a3164 commit 7a4b42c

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

psalm-baseline.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,19 @@
434434
<code>$cmd[$option]</code>
435435
<code><![CDATA[$cmd['new']]]></code>
436436
<code><![CDATA[$cmd['upsert']]]></code>
437+
<code>$decoded</code>
437438
<code><![CDATA[$options['session']]]></code>
438439
<code><![CDATA[$options['writeConcern']]]></code>
439440
</MixedAssignment>
440441
<MixedInferredReturnType>
441442
<code>array|object|null</code>
442443
</MixedInferredReturnType>
443444
<MixedMethodCall>
444-
<code>decodeIfSupported</code>
445+
<code>decode</code>
445446
<code>isInTransaction</code>
446447
</MixedMethodCall>
447448
<MixedReturnStatement>
449+
<code>$decoded</code>
448450
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
449451
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
450452
</MixedReturnStatement>

src/ChangeStream.php

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

2020
use Iterator;
21+
use MongoDB\BSON\Document;
2122
use MongoDB\Codec\DocumentCodec;
2223
use MongoDB\Driver\CursorId;
2324
use MongoDB\Driver\Exception\ConnectionException;
@@ -114,7 +115,9 @@ public function current()
114115
return $value;
115116
}
116117

117-
return $this->codec->decodeIfSupported($value);
118+
assert($value instanceof Document);
119+
120+
return $this->codec->decode($value);
118121
}
119122

120123
/** @return CursorId */

src/Operation/FindAndModify.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ public function execute(Server $server)
262262
$result = current($cursor->toArray());
263263
assert($result instanceof Document);
264264

265-
$decoded = $this->options['codec']->decodeIfSupported($result->get('value'));
266-
assert($decoded === null || is_object($decoded));
265+
$decoded = $this->options['codec']->decode($result->get('value'));
267266

268267
return $decoded;
269268
}

0 commit comments

Comments
 (0)