Skip to content

#199 - Fix PregFilterTransformer - #210

Merged
njoubert-cleverage merged 2 commits into
mainfrom
199
Sep 28, 2026
Merged

njoubert-cleverage merged 2 commits into
mainfrom
199

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #199.

PregFilterTransformer accepts an array for its replacement option (setAllowedTypes('replacement', ['string', 'array'])), but casts it to string before calling preg_filter(): an array replacement becomes the literal "Array" and raises an Array to string conversion warning, which makes the transformation fail. A list of patterns with a list of replacements, as supported by preg_filter(), is therefore unusable.

This PR:

  • pass replacement to preg_filter() without casting it;
  • as preg_filter() only accepts an array replacement with an array pattern (otherwise a TypeError), validate it when resolving the options: an array replacement with a string pattern throws an InvalidOptionsException;
  • add unit tests;
  • update docs/reference/transformers/preg_filter_transformer.md (option description, example, Notes).

The new regression tests fail on main and pass with this fix. PHPUnit, PHPStan, PHP-CS-Fixer and Rector pass.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: an array replacement currently always fails.

🤖 Generated with Claude Code

…t` is no longer cast to the string `"Array"`, and requires an array `pattern`. Update documentation, add tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit f69eace into main Sep 28, 2026
17 checks passed
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.

PregFilterTransformer casts an array replacement to the string "Array"

1 participant