Skip to content

feat: migrate more buildFilters() usages to enrichCriteria() - #84

Open
BrocksiNet wants to merge 3 commits into
FriendsOfShopware:mainfrom
BrocksiNet:feat/product-stream-builder-rector-coverage
Open

BrocksiNet wants to merge 3 commits into
FriendsOfShopware:mainfrom
BrocksiNet:feat/product-stream-builder-rector-coverage

Conversation

@BrocksiNet

@BrocksiNet BrocksiNet commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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, foreach or try.
    The rule now visits every statement list.

  • It required addFilter(...$filters) directly after the assignment and did not check whether $filters is used again, so a later count($filters) lost its variable.
    It now allows statements in between and requires $filters to be used only in that one addFilter() 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:

    $productStreamFilterCriteria = new \Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria();
    $this->productStreamBuilder->enrichCriteria($productStreamFilterCriteria, $streamId, $context);
    $filters = array_values($productStreamFilterCriteria->getFilters());

    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 to enrichCriteria() on an object that does not have it.
    Branches guarded by instanceof ProductStreamBuilderInterface, or the else of instanceof AbstractProductStreamBuilder, are left untouched; they become dead code in 6.8.

FallbackComment.php.inc now covers a ternary, since a plain return is 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.

- 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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T10:01:21.327807Z 8dd7747 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

@shyim

shyim commented Nov 17, 2026

Copy link
Copy Markdown
Member

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.
@BrocksiNet

Copy link
Copy Markdown
Contributor Author

The BCChange attributes only cover simple signature and rename changes (parameters, types, defaults, moved classes) — not replacing a method with a different API.

Here buildFilters(): array becomes enrichCriteria(Criteria $criteria, ...): void, so migrating callers requires rewriting surrounding statements (folding into addFilter() or creating a temporary Criteria). That can't be generated from an attribute, which is also why #71 keeps this as a handwritten rule.

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