Skip to content

AC-2375: Complete Twig legacy-alias -> namespaced-class migration - #134

Open
KostasNoreika wants to merge 1 commit into
masterfrom
fable/twig-namespace-migration
Open

AC-2375: Complete Twig legacy-alias -> namespaced-class migration#134
KostasNoreika wants to merge 1 commit into
masterfrom
fable/twig-namespace-migration

Conversation

@KostasNoreika

Copy link
Copy Markdown

Jira: AC-2375

Why

The Twig_* legacy aliases are removed in Twig 3, so any Twig 3 / Symfony 4+ upgrade of this repo cannot even compile until they are gone. The migration was started earlier and abandoned midway: BaseExtension::getFunctions() had one modern new TwigFunction(...) sitting directly beside 33 legacy new Twig_SimpleFunction(...) calls. This PR completes it. No upgrade is involved — twig/twig ^2.12 (resolved: v2.16.1 on a fresh composer install with Composer 2.2.9 / PHP 7.4.33) already ships the namespaced API; the legacy names are class_aliases of the exact classes substituted (verified in vendor sources: AbstractExtension.php:47, TwigFilter.php:145, TwigFunction.php:135, TwigTest.php:113, Environment.php:994).

Exact mechanical mapping

Legacy alias Namespaced class Where
Twig_Extension (extends) Twig\Extension\AbstractExtension 6 extension classes
new Twig_SimpleFilter( new Twig\TwigFilter( 11 call sites
new Twig_SimpleFunction( new Twig\TwigFunction( 62 call sites
new Twig_SimpleTest( new Twig\TwigTest( 1 call site
Twig_Environment (type-hint) Twig\Environment 3 Command classes

Files: CodeGeneratorBundle/Twig/BaseExtension, PhpGeneratorBundle/Twig/{BundleExtension, ApiMethodExtension, FieldDefinitionExtension}, JavascriptGeneratorBundle/Twig/{ApiMethodExtension, FieldDefinitionExtension}, plus the 3 commands below.

⚠️ Verifier-added scope (flagged for the human reviewer): the original task covered only the 6 extension classes. The plan verifier added Twig_EnvironmentTwig\Environment in the 3 Command classes (GenerateRestClientCommand, GenerateSymfonyBundleCommand, GeneratePackageCommand) — also removed in Twig 3, constructor type-hint + use line only. The injected twig service instance is the same object; DI needs no change (all three service XMLs register the extensions by their own Paysera FQCN).

All option arrays preserved verbatim — 23 ['needs_context' => true] occurrences across the 6 files (17 in BaseExtension), and both 'is_safe' flags. Nothing else touched: no composer.json/lock edits, no DI, no templates, no fixtures.

Proof (byte-identical output)

  • Baseline before any edit: bin/phpunit (PHPUnit 9.6.34, PHP 7.4.33 in Docker) → OK (42 tests, 1736 assertions).
  • After migration: same suite → OK (42 tests, 1736 assertions). The three golden-master tests (GenerateRestClientCommandTest, GenerateSymfonyBundleCommandTest, GeneratePackageCommandTest) compare generated output against the 910 fixture files under tests/**/Fixtures — all byte-identical, git status on tests/ clean.
  • Direct dynamic proof: bin/console php-generator:rest-client run on the account RAML fixture before and after the change into separate directories; diff -r of the two trees (9 generated files) → empty.
  • Legacy grep: git grep -E 'Twig_(Extension|SimpleFilter|SimpleFunction|SimpleTest|Environment)' -- ':!vendor' → zero matches.
  • CI steps pre-run locally in the same PHP 7.4 container: bin/phpunit ✓, bin/raml-code-generator ✓, composer run compile (box) ✓, dist/raml-code-generator.phar smoke ✓. The GitHub Actions CI workflow runs on this PR and must end green.

Draft on purpose (blast radius: medium — touches the core generation path); please review before marking ready.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates several Twig extensions and console commands to use the modern namespaced Twig classes (such as Twig\Extension\AbstractExtension, Twig\TwigFilter, Twig\TwigFunction, Twig\TwigTest, and Twig\Environment) instead of the deprecated legacy Twig_* classes. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@KostasNoreika
KostasNoreika marked this pull request as ready for review July 3, 2026 16:38
@KostasNoreika
KostasNoreika requested a review from mSprunskas July 3, 2026 16:39
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.

1 participant