Skip to content

Commit

Permalink
Use decode() instead of decodeIfSupported()
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Aug 16, 2023
1 parent c3a3164 commit 0be8dd0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,17 +434,19 @@
<code>$cmd[$option]</code>
<code><![CDATA[$cmd['new']]]></code>
<code><![CDATA[$cmd['upsert']]]></code>
<code>$decoded</code>
<code><![CDATA[$options['session']]]></code>
<code><![CDATA[$options['writeConcern']]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code>array|object|null</code>
</MixedInferredReturnType>
<MixedMethodCall>
<code>decodeIfSupported</code>
<code>decode</code>
<code>isInTransaction</code>
</MixedMethodCall>
<MixedReturnStatement>
<code>$decoded</code>
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
<code><![CDATA[is_object($result) ? ($result->value ?? null) : null]]></code>
</MixedReturnStatement>
Expand Down
6 changes: 5 additions & 1 deletion src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace MongoDB;

use Iterator;
use MongoDB\BSON\Document;
use MongoDB\Codec\DocumentCodec;
use MongoDB\Driver\CursorId;
use MongoDB\Driver\Exception\ConnectionException;
Expand All @@ -28,6 +29,7 @@
use MongoDB\Model\ChangeStreamIterator;
use ReturnTypeWillChange;

use function assert;
use function call_user_func;
use function in_array;

Expand Down Expand Up @@ -114,7 +116,9 @@ public function current()
return $value;
}

return $this->codec->decodeIfSupported($value);
assert($value instanceof Document);

return $this->codec->decode($value);
}

/** @return CursorId */
Expand Down
5 changes: 1 addition & 4 deletions src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,7 @@ public function execute(Server $server)
$result = current($cursor->toArray());
assert($result instanceof Document);

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

return $decoded;
return $this->options['codec']->decode($result->get('value'));
}

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

0 comments on commit 0be8dd0

Please sign in to comment.