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

Bug/2157 Test (and fix) Facet's aggregation pipeline with DiscriminatorMap documents #2160

Merged
merged 1 commit into from
May 28, 2020

Conversation

Ludo444
Copy link
Contributor

@Ludo444 Ludo444 commented Jan 28, 2020

Q A
Type bug
BC Break no
Fixed issues #2157

Summary

Provide a bool flag for getPipeline() if it's being called from inside the Facet and test case with DiscriminatorMap annotated document.

@malarzm malarzm added this to the 2.0.6 milestone Jan 28, 2020
@malarzm malarzm added the Bug label Jan 28, 2020
@malarzm malarzm requested a review from alcaeus January 28, 2020 18:35
@alcaeus alcaeus self-assigned this May 6, 2020
@alcaeus alcaeus changed the base branch from master to 2.0.x May 28, 2020 11:46
*/
public function getPipeline() : array
// phpcs:enable Squiz.Commenting.FunctionComment.ExtraParamComment
public function getPipeline(/* bool $applyFilters = true */) : array
Copy link
Member

Choose a reason for hiding this comment

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

Since we need to preserve BC, we can't add a new method argument. Instead, we add it commented and use func_num_args to check for it being given. The if below then emulates strict typing, throwing an exception if we get anything but a bool.

Note that I've also changed the logic of the argument: instead of calling it isFacet, we call it applyFilters. This is mainly because upcoming changes to the $lookup stage will require us using the same functionality, so isFacet would be the wrong name.

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 we'd do just fine with new argument with default value, but since you've gone the extra mile with this approach let's keep it 👍 The only possible downside I see is PHPStan complaining about passing a parameter that is not there. Unless it'll take phpdoc's word?

Copy link
Member

Choose a reason for hiding this comment

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

It should take PHPDoc's word. However, adding a new parameter, even with default value, is a BC break: https://3v4l.org/jobIX

Copy link
Member

Choose a reason for hiding this comment

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

It sure is, my point was more "who extends a builder" :) Sorry for not making myself clear

Copy link
Member

Choose a reason for hiding this comment

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

OTOH the builder is not final so my point was invalid

if ($this->getStage(0) instanceof Stage\GeoNear) {
$pipeline[0]['$geoNear']['query'] = $this->applyFilters($pipeline[0]['$geoNear']['query']);
} elseif ($this->getStage(0) instanceof Stage\IndexStats) {
if ($this->getStage(0) instanceof Stage\IndexStats) {
Copy link
Member

Choose a reason for hiding this comment

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

Applied some formatting and early exits here to avoid unnecessary nesting.

@alcaeus alcaeus requested a review from malarzm May 28, 2020 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants