Skip to content

Fix signatures of bsonSerialize() methods #1156

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 2 commits into from
Sep 8, 2023

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Sep 8, 2023

mongodb/mongo-php-driver#1449 changed the tentative return type of MongoDB\BSON\Serializable to no longer allow any object (which was incorrect as we never supported returning any object other than stdClass instances), instead restricting it to stdClass instances. This PR deals with the resulting deprecation notices emitted on PHP 8.1 and newer.

@alcaeus alcaeus requested a review from GromNaN September 8, 2023 09:05
@alcaeus alcaeus self-assigned this Sep 8, 2023
@@ -66,7 +67,7 @@ public function __construct(array $index)
* @see \MongoDB\Collection::createSearchIndexes()
* @see https://php.net/mongodb-bson-serializable.bsonserialize
*/
public function bsonSerialize(): object
public function bsonSerialize(): stdClass
{
return (object) $this->index;
Copy link
Member

Choose a reason for hiding this comment

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

The psalm inferred type is incorrect. $this->index is an array, so (object) $this->index cannot be anything different that stdClass.
Let's add this warnings to the baseline.

src/Model/SearchIndexInput.php:70:38: MoreSpecificReturnType: The declared return type 'stdClass' for MongoDB\Model\SearchIndexInput::bsonSerialize is more specific than the inferred return type 'object' (see https://psalm.dev/070)

Copy link
Member

@GromNaN GromNaN Sep 8, 2023

Choose a reason for hiding this comment

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

Known issue: vimeo/psalm#10019

@alcaeus alcaeus merged commit f38224d into mongodb:master Sep 8, 2023
@alcaeus alcaeus deleted the fix-bson-signatures branch September 8, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants