Skip to content
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

Remove compatibility layer for CursorId deprecation #1425

Closed
wants to merge 3 commits into from

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Sep 19, 2024

This pull request removes the compatibility layer introduced to handle the deprecation of MongoDB\Driver\CursorId. To work around psalm not having updated stubs, we introduce stubs temporarily until the stubs are properly updated.

Note that due to an issue in psalm, we still need a workaround for ChangeStreamIterator::getInnerIterator. I've created vimeo/psalm#11100 to fix this issue, and the errors are suppressed in the baseline until a fix is released.

@alcaeus alcaeus requested a review from jmikola September 19, 2024 10:58
@alcaeus alcaeus requested a review from a team as a code owner September 19, 2024 10:58
src/Model/ChangeStreamIterator.php Dismissed Show dismissed Hide dismissed
src/Model/ChangeStreamIterator.php Dismissed Show dismissed Hide dismissed
@alcaeus
Copy link
Member Author

alcaeus commented Sep 19, 2024

The CI build fails as we're not testing with the 2.0 version yet. This depends on mongodb/mongo-php-driver#1672. It may be necessary to wrap this work into #1391.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Some questions, but I don't think I have any actionable feedback.

{
/**
* @return TValue|null
* @psalm-ignore-nullable-return
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, @psalm-ignore-nullable-return tells Psalm to never consider a null return value. But current() and key() can certainly return null if valid() is false. Why needn't we consider that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was blatantly copied over from psalm's iterator stubs. The way I see it, this is a shortcoming of the original interface. The interface doesn't specify whether current and key should throw when on an invalid position, and most iterators return null instead. IMO, we should throw, but I imagine a lot of code isn't exactly built to handle throwing in the methods. At the same time, we do expect people to not call current and key without checking that the iterator is on a valid position, hence that annotation.

For immutable classes, the psalm-assert-if-true annotation would solve this, but since next has to reset a previously memoized result from valid I'm not sure if psalm can handle it. It would definitely be a worthwhile improvement.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation.

I imagine throwing would be incredibly annoying, as manual iteration is already a complicated subject. I reckon the average PHP developer isn't familiar with the sequence of method calls to mimic a foreach loop.

Not so much the case with our write result getters relying on isAcknowledged(), as that's easier to wrap one's head around.

stubs/Driver/CursorInterface.stub.php Show resolved Hide resolved
'MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead.',
$deprecations[1][1],
);
}
Copy link
Member

Choose a reason for hiding this comment

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

@alcaeus
Copy link
Member Author

alcaeus commented Sep 20, 2024

Folded into #1391

@alcaeus alcaeus closed this Sep 20, 2024
@alcaeus alcaeus deleted the remove-cursorid-compat-layer branch September 20, 2024 08:02
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