Skip to content

PHPLIB-1161: Leverage array_key_first in functions #1101

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
Jun 12, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jun 12, 2023

Fix PHPLIB-1161

The polyfill is already installed.

@GromNaN GromNaN requested review from jmikola and alcaeus June 12, 2023 09:20
@@ -319,11 +317,9 @@ function is_last_pipeline_operator_write(array $pipeline): bool
return false;
}

$lastOp = document_to_array($lastOp);
$key = array_key_first(document_to_array($lastOp));
Copy link
Member Author

Choose a reason for hiding this comment

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

I had a doubt whether it's array_key_first or array_key_last. But reset moves the cursor to the first element.

A new test case may be necessary as it doesn't fail when I change to get the first or the last key.

Copy link
Member Author

@GromNaN GromNaN Jun 12, 2023

Choose a reason for hiding this comment

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

I think the $lastOp array must contain exactly 1 item. That's why it doesn't matter. We could even have used key() directly without reset().

Copy link
Member

Choose a reason for hiding this comment

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

I think the $lastOp array must contain exactly 1 item.

That's correct - we're assuming this is an aggregation pipeline stage which only contains one key.

@GromNaN GromNaN merged commit 316d6d6 into mongodb:master Jun 12, 2023
@GromNaN GromNaN deleted the PHPLIB-1161 branch June 12, 2023 11:18
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