Repository navigation
feat: migrate more buildFilters() usages to enrichCriteria() - #84
BrocksiNet wants to merge 3 commits into
Conversation
- Visit every statement list, so calls inside if, foreach, try and closures are migrated too. - Match `$filters = buildFilters(); ... addFilter(...$filters)` with other statements in between, as long as $filters is used only in that addFilter() call. - Only rewrite addFilter() calls with a single unpacked argument, other arguments were dropped before. - Migrate every other usage through a temporary Criteria, which returns the same filters as the AbstractProductStreamBuilder::buildFilters() bridge. Calls in conditionally evaluated expressions still get the TODO comment. - Leave the legacy branch of dual-path code that checks the builder with instanceof untouched.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8dd774788d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
i would tbh except @keulinho bcchange attributes would be able to handle these kind of things 🤔 |
- Visit each variable scope (method, function, closure, file) and walk nested statement lists from there, so variable checks see the whole scope and legacy instanceof branches are skipped with all their nested statements and closures. - Fold `$filters = buildFilters(); ... addFilter(...$filters)` only when $filters is used nowhere else in the scope and the statements in between neither touch what the call reads nor leave early. Otherwise migrate the assignment in place through a temporary criteria. - Give every hoisted call its own temporary criteria variable that does not collide with a variable of the scope. - Do not hoist a call when something with side effects runs before it in the same statement, add the TODO comment instead.
|
The Here |
…uilder-rector-coverage
Shopware 6.8 removes
ProductStreamBuilderInterface::buildFilters().About 4% of Shopware Store extensions still call it, so this rule decides how smooth the 6.8 upgrade is for them.
I ran the 6.8 set over the 159 store extensions that reference the interface.
The current rule fully migrated 7 of them and left 218 TODO comments.
With this change, 155 are fully migrated with 0 TODO comments, and every changed file passes
php -l.Of the other 4, two declare the builder property without a type, so Rector cannot know what it is, one is the dual-path case below, and one only has an unused import.
What blocked the current rule, and what changed:
It only looked at the top-level statements of a method.
Most calls sit inside
if,foreachortry.The rule now visits every statement list.
It required
addFilter(...$filters)directly after the assignment and did not check whether$filtersis used again, so a latercount($filters)lost its variable.It now allows statements in between and requires
$filtersto be used only in that oneaddFilter()call.addFilter($other, ...$builder->buildFilters())dropped$other.Only single-argument
addFilter()calls are rewritten directly now.Everything else (return values,
array_merge(),new MultiFilter(..., $filters), loops) is migrated through a temporary criteria:That is exactly what the
AbstractProductStreamBuilder::buildFilters()bridge does in Shopware 6.7.16, so the result is the same.Calls inside
&&,||,??, ternaries,match, nullsafe calls and closures are not moved, because that would change when they run; they keep the TODO comment.Code that already supports both APIs (
if ($builder instanceof AbstractProductStreamBuilder) { enrichCriteria } else { buildFilters }) had its legacy branch rewritten toenrichCriteria()on an object that does not have it.Branches guarded by
instanceof ProductStreamBuilderInterface, or theelseofinstanceof AbstractProductStreamBuilder, are left untouched; they become dead code in 6.8.FallbackComment.php.incnow covers a ternary, since a plainreturnis migrated (HoistReturnValue.php.inc).The type part of the migration has its own fixes in #83; the two PRs are independent.
Tested with PHPUnit on Rector 2.8.0 and 2.8.5, plus PHPStan and php-cs-fixer.