[Symfony 7.3] Merge AsTwigFilter/AsTwigFunction rules into single rule, add getTests() support - #1027
Merged
Merged
Conversation
…FiltersAndFunctionsToAsTwigAttributeRector Separate rules per get*() method could never convert a class that declares more than one of them: each rule bailed out in stillRequiresAbstractExtension(), because the sibling method kept the class bound to AbstractExtension. The merged rule collects conversions for getFilters(), getFunctions() and getTests() in a single pass, validates them all, and only then drops "extends AbstractExtension". Also adds getTests() -> #[AsTwigTest] support, with per-method option mapping (#[AsTwigTest] has no isSafe/preservesSafety options).
This was referenced Aug 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetFiltersToAsTwigFilterAttributeRectorandGetFunctionsToAsTwigFunctionAttributeRectorcould never convert a class that declares bothgetFilters()andgetFunctions().Each rule checks
stillRequiresAbstractExtension()before converting - and the sibling method is exactly such a blocker. So the filter rule bailed becausegetFunctions()was still there, and the function rule bailed becausegetFilters()was still there. Very common shape in real Twig extensions.This merges both into
GetFiltersAndFunctionsToAsTwigAttributeRector, which collects conversions ofgetFilters(),getFunctions()andgetTests()in one pass, validates them all, and only then removesextends AbstractExtension.Also adds
getTests()->#[AsTwigTest], with per-method option mapping (#[AsTwigTest]has noisSafe/preservesSafety/preEscape).Before
After
Both old rules are removed and replaced in the
twig/twig 3.21composer-based set; their fixtures are merged into the new rule test.Skip behaviour is unchanged: if any present
get*()method cannot be fully converted (closures, injected-service callables, built-in name overrides,GlobalsInterface, token parsers, ...), the whole class is left alone, sinceextends AbstractExtensionmust stay.