Skip to content

Commit

Permalink
Encode documents before type checks
Browse files Browse the repository at this point in the history
This commit also changes the behaviour to use encode() instead of encodeIfSupported(), requiring documents to be encodable by the given codec in order to be inserted/updated.
  • Loading branch information
alcaeus committed Aug 2, 2023
1 parent dacdf18 commit 7263a62
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 275 deletions.
36 changes: 16 additions & 20 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
<code>$args[0]</code>
<code>$args[0]</code>
<code>$args[0]</code>
<code>$args[0]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
Expand Down Expand Up @@ -236,8 +238,6 @@
<code><![CDATA[$args[2]['upsert']]]></code>
</MixedArrayAccess>
<MixedArrayAssignment>
<code>$args[0]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
Expand All @@ -250,15 +250,15 @@
<code>$args[2]</code>
<code><![CDATA[$args[2]['multi']]]></code>
<code><![CDATA[$args[2]['multi']]]></code>
<code>$operations[$i][$type][0]</code>
<code>$operations[$i][$type][1]</code>
<code>$operations[$i][$type][1]</code>
<code>$operations[$i][$type][2]</code>
<code>$operations[$i][$type][2]</code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$args</code>
<code>$args</code>
<code>$args[0]</code>
<code>$args[1]</code>
<code>$args[2]</code>
<code>$args[2]</code>
<code>$insertedIds[$i]</code>
Expand All @@ -270,8 +270,6 @@
<code><![CDATA[$options['writeConcern']]]></code>
</MixedAssignment>
<MixedMethodCall>
<code>encodeIfSupported</code>
<code>encodeIfSupported</code>
<code>isInTransaction</code>
</MixedMethodCall>
<MixedOperand>
Expand Down Expand Up @@ -472,10 +470,9 @@
<MixedAssignment>
<code><![CDATA[$options['fields']]]></code>
</MixedAssignment>
<RedundantConditionGivenDocblockType>
<code>assert(is_array($replacement) || is_object($replacement))</code>
<code>is_array($replacement)</code>
</RedundantConditionGivenDocblockType>
<PossiblyInvalidArgument>
<code>$replacement</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/FindOneAndUpdate.php">
<MixedAssignment>
Expand All @@ -484,16 +481,17 @@
</file>
<file src="src/Operation/InsertMany.php">
<MixedAssignment>
<code>$document</code>
<code>$insertedIds[$i]</code>
<code>$options[$option]</code>
<code><![CDATA[$options['session']]]></code>
<code><![CDATA[$options['writeConcern']]]></code>
</MixedAssignment>
<MixedMethodCall>
<code>encodeIfSupported</code>
<code>isInTransaction</code>
</MixedMethodCall>
<PossiblyInvalidArgument>
<code>$document</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/InsertOne.php">
<MixedAssignment>
Expand All @@ -505,10 +503,9 @@
<MixedMethodCall>
<code>isInTransaction</code>
</MixedMethodCall>
<RedundantConditionGivenDocblockType>
<code>assert(is_array($document) || is_object($document))</code>
<code>is_array($document)</code>
</RedundantConditionGivenDocblockType>
<PossiblyInvalidArgument>
<code>$document</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/ListIndexes.php">
<MixedAssignment>
Expand Down Expand Up @@ -557,10 +554,9 @@
</MixedMethodCall>
</file>
<file src="src/Operation/ReplaceOne.php">
<RedundantConditionGivenDocblockType>
<code>assert(is_array($replacement) || is_object($replacement))</code>
<code>is_array($replacement)</code>
</RedundantConditionGivenDocblockType>
<PossiblyInvalidArgument>
<code>$replacement</code>
</PossiblyInvalidArgument>
</file>
<file src="src/Operation/Update.php">
<MixedArgument>
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ public function getWriteConcern()
*
* @see InsertMany::__construct() for supported options
* @see https://mongodb.com/docs/manual/reference/command/insert/
* @param array[]|object[] $documents The documents to insert
* @param array $options Command options
* @param list<object|array> $documents The documents to insert
* @param array $options Command options
* @return InsertManyResult
* @throws InvalidArgumentException for parameter/option parsing errors
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
Expand Down
Loading

0 comments on commit 7263a62

Please sign in to comment.