Skip to content

PHPLIB-1122: Support Document and PackedArray objects in public APIs #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"ext-json": "*",
"ext-mongodb": "^1.16.0",
"jean85/pretty-package-versions": "^2.0.1",
"symfony/polyfill-php80": "^1.19"
"symfony/polyfill-php73": "^1.27",
"symfony/polyfill-php80": "^1.27"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7",
Expand Down
96 changes: 6 additions & 90 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="examples/aggregate.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>toRelaxedExtendedJSON(fromPHP($document))</code>
</MixedReturnStatement>
</file>
<file src="examples/bulk.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>toRelaxedExtendedJSON(fromPHP($document))</code>
</MixedReturnStatement>
</file>
<file src="examples/changestream.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>toRelaxedExtendedJSON(fromPHP($document))</code>
</MixedReturnStatement>
</file>
<file src="examples/command_logger.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>toRelaxedExtendedJSON(fromPHP($document))</code>
</MixedReturnStatement>
</file>
<file src="examples/typemap.php">
<PropertyNotSetInConstructor occurrences="5">
<code>$address</code>
Expand All @@ -41,14 +9,6 @@
<code>$type</code>
</PropertyNotSetInConstructor>
</file>
<file src="examples/with_transaction.php">
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>toRelaxedExtendedJSON(fromPHP($document))</code>
</MixedReturnStatement>
</file>
<file src="src/Client.php">
<MixedArgument occurrences="1">
<code>$driverOptions['driver'] ?? []</code>
Expand All @@ -57,16 +17,6 @@
<code>$mergedDriver['platform']</code>
</MixedAssignment>
</file>
<file src="src/Collection.php">
<MixedArgument occurrences="3">
<code>$encryptedFields['eccCollection'] ?? 'enxcol_.' . $this-&gt;collectionName . '.ecc'</code>
<code>$encryptedFields['ecocCollection'] ?? 'enxcol_.' . $this-&gt;collectionName . '.ecoc'</code>
<code>$encryptedFields['escCollection'] ?? 'enxcol_.' . $this-&gt;collectionName . '.esc'</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$encryptedFields</code>
</MixedAssignment>
</file>
<file src="src/Command/ListCollections.php">
<MixedAssignment occurrences="2">
<code>$cmd[$option]</code>
Expand All @@ -79,21 +29,6 @@
<code>$options['session']</code>
</MixedAssignment>
</file>
<file src="src/Database.php">
<MixedArgument occurrences="6">
<code>$encryptedFields['eccCollection'] ?? 'enxcol_.' . $collectionName . '.ecc'</code>
<code>$encryptedFields['eccCollection'] ?? 'enxcol_.' . $collectionName . '.ecc'</code>
<code>$encryptedFields['ecocCollection'] ?? 'enxcol_.' . $collectionName . '.ecoc'</code>
<code>$encryptedFields['ecocCollection'] ?? 'enxcol_.' . $collectionName . '.ecoc'</code>
<code>$encryptedFields['escCollection'] ?? 'enxcol_.' . $collectionName . '.esc'</code>
<code>$encryptedFields['escCollection'] ?? 'enxcol_.' . $collectionName . '.esc'</code>
</MixedArgument>
<MixedAssignment occurrences="3">
<code>$encryptedFields</code>
<code>$encryptedFields</code>
<code>$options['encryptedFields']</code>
</MixedAssignment>
</file>
<file src="src/Exception/BadMethodCallException.php">
<UnsafeInstantiation occurrences="2">
<code>new static(sprintf('%s is immutable', $class))</code>
Expand Down Expand Up @@ -139,14 +74,10 @@
<code>drop</code>
<code>rename</code>
</MissingReturnType>
<MixedArgument occurrences="3">
<code>$id</code>
<MixedArgument occurrences="2">
<code>$options['revision']</code>
<code>$options['revision']</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$id</code>
</MixedAssignment>
</file>
<file src="src/GridFS/Exception/CorruptFileException.php">
<UnsafeInstantiation occurrences="4">
Expand All @@ -157,24 +88,12 @@
</UnsafeInstantiation>
</file>
<file src="src/GridFS/Exception/FileNotFoundException.php">
<MixedArgument occurrences="1">
<code>$json</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$json</code>
</MixedAssignment>
<UnsafeInstantiation occurrences="2">
<code>new static(sprintf('File "%s" not found in "%s"', $json, $namespace))</code>
<code>new static(sprintf('File with name "%s" and revision "%d" not found in "%s"', $filename, $revision, $namespace))</code>
</UnsafeInstantiation>
</file>
<file src="src/GridFS/Exception/StreamException.php">
<MixedArgument occurrences="1">
<code>$idString</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$idString</code>
</MixedAssignment>
<UnsafeInstantiation occurrences="3">
<code>new static(sprintf('Downloading file from "%s" to "%s" failed. GridFS filename: "%s"', $sourceMetadata['uri'], $destinationMetadata['uri'], $filename))</code>
<code>new static(sprintf('Downloading file from "%s" to "%s" failed. GridFS identifier: "%s"', $sourceMetadata['uri'], $destinationMetadata['uri'], $idString))</code>
Expand Down Expand Up @@ -384,7 +303,7 @@
<DocblockTypeContradiction occurrences="1">
<code>is_array($operation)</code>
</DocblockTypeContradiction>
<MixedArgument occurrences="11">
<MixedArgument occurrences="12">
<code>$args</code>
<code>$args</code>
<code>$args</code>
Expand All @@ -395,6 +314,7 @@
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[1]</code>
<code>$args[2]</code>
</MixedArgument>
<MixedArrayAccess occurrences="25">
Expand Down Expand Up @@ -629,10 +549,9 @@
<code>$this-&gt;options['typeMap']</code>
<code>$this-&gt;options['writeConcern']</code>
</MixedArgument>
<MixedAssignment occurrences="6">
<MixedAssignment occurrences="5">
<code>$cmd[$option]</code>
<code>$cmd['new']</code>
<code>$cmd['update']</code>
<code>$cmd['upsert']</code>
<code>$options['session']</code>
<code>$options['writeConcern']</code>
Expand Down Expand Up @@ -834,11 +753,9 @@
</MixedAssignment>
</file>
<file src="src/functions.php">
<DocblockTypeContradiction occurrences="4">
<DocblockTypeContradiction occurrences="2">
<code>! is_array($document) &amp;&amp; ! is_object($document)</code>
<code>is_array($document)</code>
<code>is_array($document)</code>
<code>is_array($out)</code>
</DocblockTypeContradiction>
<MixedArgument occurrences="1">
<code>$wireVersionForWriteStageOnSecondary</code>
Expand All @@ -853,9 +770,8 @@
<code>$typeMap['fieldPaths'][$fieldPath]</code>
<code>$typeMap['fieldPaths'][substr($fieldPath, 0, -2)]</code>
</MixedArrayAssignment>
<MixedAssignment occurrences="7">
<MixedAssignment occurrences="6">
<code>$element[$key]</code>
<code>$lastOp</code>
<code>$type</code>
<code>$type</code>
<code>$typeMap['fieldPaths'][$fieldPath . '.' . $existingFieldPath]</code>
Expand Down
9 changes: 5 additions & 4 deletions src/Operation/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use function is_integer;
use function is_object;
use function is_string;
use function MongoDB\document_to_array;
use function trigger_error;

use const E_USER_DEPRECATED;
Expand Down Expand Up @@ -427,10 +428,10 @@ private function createQueryOptions(): array
}
}

$modifiers = empty($this->options['modifiers']) ? [] : (array) $this->options['modifiers'];

if (! empty($modifiers)) {
$options['modifiers'] = $modifiers;
if (! empty($this->options['modifiers'])) {
/** @psalm-var array|object */
$modifiers = $this->options['modifiers'];
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
}

return $options;
Expand Down
6 changes: 3 additions & 3 deletions src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ private function createCommandDocument(): array
}

if (isset($this->options['update'])) {
$cmd['update'] = is_pipeline($this->options['update'])
? $this->options['update']
: (object) $this->options['update'];
/** @psalm-var array|object */
$update = $this->options['update'];
$cmd['update'] = is_pipeline($update) ? $update : (object) $update;
}

foreach (['arrayFilters', 'bypassDocumentValidation', 'comment', 'hint', 'maxTimeMS'] as $option) {
Expand Down
Loading