Skip to content

Commit 2ac2b53

Browse files
committed
Use decode() instead of decodeIfSupported()
1 parent c3a3164 commit 2ac2b53

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

psalm-baseline.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,11 @@
441441
<code>array|object|null</code>
442442
</MixedInferredReturnType>
443443
<MixedMethodCall>
444-
<code>decodeIfSupported</code>
444+
<code>decode</code>
445445
<code>isInTransaction</code>
446446
</MixedMethodCall>
447447
<MixedReturnStatement>
448+
<code><![CDATA[$this->options['codec']->decode($result->get('value'))]]></code>
448449
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
449450
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
450451
</MixedReturnStatement>

src/ChangeStream.php

Lines changed: 5 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;
@@ -28,6 +29,7 @@
2829
use MongoDB\Model\ChangeStreamIterator;
2930
use ReturnTypeWillChange;
3031

32+
use function assert;
3133
use function call_user_func;
3234
use function in_array;
3335

@@ -114,7 +116,9 @@ public function current()
114116
return $value;
115117
}
116118

117-
return $this->codec->decodeIfSupported($value);
119+
assert($value instanceof Document);
120+
121+
return $this->codec->decode($value);
118122
}
119123

120124
/** @return CursorId */

src/Operation/FindAndModify.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +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));
267-
268-
return $decoded;
265+
return $this->options['codec']->decode($result->get('value'));
269266
}
270267

271268
if (isset($this->options['typeMap'])) {

0 commit comments

Comments
 (0)