Skip to content

Fix psalm errors #1209

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 1 commit into from
Dec 18, 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
18 changes: 10 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="docs/examples/encryption/csfle-explicit_encryption.php">
<MixedArgument>
<code><![CDATA[$clientEncryption->decrypt($document->encryptedField)]]></code>
Expand Down Expand Up @@ -114,10 +114,16 @@
<InvalidParamDefault>
<code><![CDATA[class-string<ArrayIterator<string,mixed>>|class-string<ArrayObject<string,mixed>>]]></code>
</InvalidParamDefault>
<LessSpecificReturnStatement>
<code><![CDATA[(object) $this->getArrayCopy()]]></code>
</LessSpecificReturnStatement>
<MixedAssignment>
<code>$this[$key]</code>
<code>$value</code>
</MixedAssignment>
<MoreSpecificReturnType>
<code>stdClass</code>
</MoreSpecificReturnType>
Comment on lines +117 to +126
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LessSpecificReturnStatement and MoreSpecificReturnType are due to vimeo/psalm#8187. In essence, Psalm takes the return value of (object) [] to be object, even though it is stdClass.

</file>
<file src="src/Model/BSONIterator.php">
<MixedArgument>
Expand Down Expand Up @@ -509,6 +515,9 @@
</MixedAssignment>
</file>
<file src="src/Operation/FindOneAndReplace.php">
<MixedArgument>
<code><![CDATA[$options['codec'] ?? null]]></code>
</MixedArgument>
Comment on lines +518 to +520
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this errors in that one specific file - it works in all other files where we have the same checks on the codec option and then use it in a typed context 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't reproduce.
https://psalm.dev/r/609a35bce9

<MixedAssignment>
<code><![CDATA[$options['fields']]]></code>
</MixedAssignment>
Expand Down Expand Up @@ -639,13 +648,6 @@
<code><![CDATA[$this->changeStreamOptions['startAfter']]]></code>
</MixedReturnStatement>
</file>
<file src="src/PsrLogAdapter.php">
<MethodSignatureMismatch>
<code>$domain</code>
<code>$level</code>
<code>$message</code>
</MethodSignatureMismatch>
</file>
<file src="src/UpdateResult.php">
<MixedAssignment>
<code>$id</code>
Expand Down
3 changes: 2 additions & 1 deletion src/Model/BSONDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use MongoDB\BSON\Serializable;
use MongoDB\BSON\Unserializable;
use ReturnTypeWillChange;
use stdClass;

use function MongoDB\recursive_copy;

Expand Down Expand Up @@ -78,7 +79,7 @@ public static function __set_state(array $properties)
* Serialize the document to BSON.
*
* @see https://php.net/mongodb-bson-serializable.bsonserialize
* @return object
* @return stdClass
*/
#[ReturnTypeWillChange]
public function bsonSerialize()
Expand Down