Skip to content

[composer-based] Add Twig composer-based set - #996

Merged
TomasVotruba merged 1 commit into
mainfrom
twig-composer-based-set
Aug 3, 2026
Merged

[composer-based] Add Twig composer-based set#996
TomasVotruba merged 1 commit into
mainfrom
twig-composer-based-set

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds config/sets/twig/composer-based.php, the Twig counterpart of config/sets/symfony/composer-based.php. Rules and rule configuration are bound to the twig/twig version installed in the analysed project, so a direct upgrade from any older Twig version is covered by a single set, instead of chaining twig112twig127 → … → twig30.

The existing per-version Twig sets are left untouched.

What the set does

 final class SomeTwigUse
 {
-    public function run(Twig_Environment $twigEnvironment)
+    public function run(\Twig\Environment $twigEnvironment)
     {
-        return new Twig_SimpleFilter('some_filter', 'strlen');
+        return new \Twig\TwigFilter('some_filter', 'strlen');
     }
 }

Version bonds

twig/twig rules
>=1.12 <1.40 Twig_Function/Twig_Filter/Twig_TestTwig_Simple* renames
>=1.27 Twig_Node/Twig_Template/Twig_Error method renames
>=1.34 SimpleFunctionAndFilterRector
>=1.40 underscore → namespaced class renames
>=3.0 getFilters()/getFunctions()/getTests() array return types

Two spots where the flat set cannot be a literal copy of the version sets, as all rules now run at once:

  • the 1.12 renames are capped at <1.40 — from 1.40 on, the namespaced rename maps the very same classes directly to Twig\TwigFunction etc., so keeping both would make RenameClassRector ping-pong between Twig_Function and Twig_SimpleFunction
  • for the same reason the Twig 2.0 set (Twig_SimpleFilterTwig_Filter) is not repeated; both underscore names already lead to the same namespaced class in the >=1.40 group
  • Twig_Function_Node had no namespaced target in the version sets (it went through Twig_SimpleFunction), so the >=1.40 group maps it to Twig\TwigFunction directly, to keep the same end state
  • the Twig_Tests_EnvironmentTest_ExtensionTwig\Tests\EnvironmentTest\Extensio mapping was left out, as the target class name is truncated

Rule bonding

SimpleFunctionAndFilterRector now implements ComposerPackageConstraintInterface (twig/twig >=1.34), same as the other bonded rules. Its test reads the version from a standalone composer.json.

twig/twig is added to require-dev, so the composer-bound configuration is active in tests — without it the whole set is skipped and untestable.

Adds config/sets/twig/composer-based.php, mirroring the Symfony one:
rules and rule configuration bound to the twig/twig version installed
in the analysed project, so a direct upgrade from any older Twig
version is covered by a single set.

The existing per-version Twig sets are left untouched.
@TomasVotruba
TomasVotruba merged commit a6a3eee into main Aug 3, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the twig-composer-based-set branch August 3, 2026 15:52
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.

1 participant