-
Notifications
You must be signed in to change notification settings - Fork 20
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
WIP: V3 - refactoring #7 #12
Conversation
pionl
commented
Mar 17, 2022
- upgrade code to PHP 8.0 with strict types
- reactor with automatic downgrade script
- phpstan 8 + phpcs fixer
- Upgrade queries / aggregations to use strict constructors
- Add GeoBoundingBoxQuery
- Add HistogramAggregation / WidthHistogramAggregation
- Add collapse support
- Improve sub aggregation on aggregations
Started refactoring my code base. At this moment most of the time is rewriting Filters to Query. Its not bad and its quite easy and the code looks pretty now :) 👍 new BoolQuery(should: [
new BoolQuery(filter: [
new RangeQuery(field: PriceTermsIndex::FROM, gte: $this->from->toDateString()),
new RangeQuery(field: PriceTermsIndex::TO, lte: $this->to->toDateString()),
]),
// If the current year has no price set we want to return it as there was no price (will work if
// HasNumberOfNights->allowTermsWithZeroNights is true)
new TermQuery(PriceTermsIndex::NUMBER_OF_NIGHTS_RAW, 0),
]), Aggregations were easy. |
This is great ! Thanks 🙏 IMHO the code is even prettier when using the static factory ;) |
Need to rename the branch from v3 (composer will not allow me to reference branch name with v in it). Do you know how to do it? Otherwise I will have to make a new PR. Is the code ok for you? (the direction). Am I missing something? |
You can rename your branch with The direction seems OK to me but he PR is quite large to review. Maybe you can split in mutliple PRs ? |
I did rename it but the PR got close but cant edit the PR branch. About the code review - not sure if I can do it as proposed. It is mixed because rector / phpcs fixer improved the code quality.
Any way, how migrate my codebase (apx 50 filters -> queries) and it works 👍 |
I think im near to finishing all changes, I've made some tweaks I needed to be able to fully customize / use query builder. I can try to separate the changes. |
@pionl I've started to review this PR. One question so far : in the constructors sometime you set a private property and othertime a public one. Is there a particular reason for having both ? Shouldn't we use only private properties ? |
$containerConfigurator->import(SetList::SYMPLIFY); | ||
$containerConfigurator->import(SetList::COMMON); | ||
$containerConfigurator->import(SetList::CLEAN_CODE); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the Symfony ruleset please 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I thought has this setup for Symfony related stuff but I will check it 👍 Thanks for your time! I will try this week to split it as requested :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to leave the 3 rules?
I've switched to symfony and it made change in yoda_style
.
Is this what you want?
- if (empty($this->innerHits) === false) {
+ if (false === empty($this->innerHits)) {
$result['inner_hits'] = array_map(fn (InnerHit $hit) => $hit->build(), $this->innerHits);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's perfect. I work with yoda condition for so long I can't go back !
But in your exemple I can't figure why you don't use a simple if (!empty($this->innerHits))
. The empty function only return bool so you don't have to be strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in our team we are do like to always use a strict comparison even for bools. We find it more readable than finding !
symbol at the start
Public - I'll check which one and try to find usage. I think I've needed them in some cases (I'm doing some additional logic -> when this aggregation is used do this with source, etc). Maybe we can expose all to public? Support set/get + "public property" ? Or use set/get everywhere? I can make the changes with your preference. Thank you, Martin |
I prefer all privates with getter/setter, I think users will expect to have theses. |
No need to separate anymore, I reviewed the whole thing already :) |
Ok I'll make the changes :) |
Also I've moved the "downgrade" proof of concept to different branch |
Great work ! Thanks @pionl |
Thank you for the cooperation! |