Skip to content

[Symfony 7.3] Gate GetFiltersAndFunctionsToAsTwigAttributeRector on symfony/twig-bridge 7.3, not twig alone - #1050

Merged
TomasVotruba merged 4 commits into
mainfrom
gate-twig-attribute-rule-on-symfony-7-3
Aug 20, 2026
Merged

[Symfony 7.3] Gate GetFiltersAndFunctionsToAsTwigAttributeRector on symfony/twig-bridge 7.3, not twig alone#1050
TomasVotruba merged 4 commits into
mainfrom
gate-twig-attribute-rule-on-symfony-7-3

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9856.

Problem

GetFiltersAndFunctionsToAsTwigAttributeRector was bonded to twig/twig >=3.21 only. But the attributes it introduces (#[AsTwigFilter], #[AsTwigFunction], #[AsTwigTest]) are autoregistered by Symfony only from 7.3 (symfony/twig-bridge). On Symfony 6.4 with twig 3.28, the twig constraint passes, the rule strips TwigExtension + getFilters()/getFunctions(), and every filter/function silently disappears.

// Symfony 6.4, twig 3.28 -> rule wrongly applied, filters lost
class AppExtension extends AbstractExtension
{
    public function getFilters(): array
    {
        return [new TwigFilter('foo', [$this, 'foo'])];
    }
}

Fix

Gate on both packages, so the rule runs only where the attributes actually work:

public function provideComposerPackageConstraint(): array
{
    return [
        new ComposerPackageConstraint('twig/twig', '>=3.21'),
        new ComposerPackageConstraint('symfony/twig-bridge', '>=7.3'),
    ];
}

Depends on

Multiple-constraint support: rectorphp/rector-src#8355. CI here stays red until that merges into rector-src main (pulled as dev-main).

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 20, 2026 15:43
@TomasVotruba
TomasVotruba merged commit 79c9c0a into main Aug 20, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the gate-twig-attribute-rule-on-symfony-7-3 branch August 20, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

GetFiltersAndFunctionsToAsTwigAttributeRector is applied in Symfony 6, but is not supported

2 participants