Skip to content

[Deprecation] Deprecate TemplateAnnotationToThisRenderRector as risky, annotation based and better tailored to the project - #989

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-template-annotation-to-this-render
Aug 2, 2026
Merged

[Deprecation] Deprecate TemplateAnnotationToThisRenderRector as risky, annotation based and better tailored to the project#989
TomasVotruba merged 1 commit into
mainfrom
deprecate-template-annotation-to-this-render

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

TemplateAnnotationToThisRenderRector turns a @Template/#[Template] annotation into an explicit $this->render() call. To do that it has to answer two questions that only the project itself can answer.

1) Where does the template live? The rule guesses the path from bundle and controller naming conventions:

 final class SomeController
 {
-    /**
-     * @Template()
-     */
     public function indexAction()
     {
+        return $this->render('index.html.twig');
     }
 }

The 'index.html.twig' is derived from the class name, namespace and an optional bundle lookup. Any project that does not follow the conventions the guesser assumes gets a path to a template that does not exist, and the breakage only shows up at runtime.

2) Is this return template variables, or an already built Response? The rule inspects the return type of every return statement and rewrites only those it believes carry template variables:

 public function detailAction()
 {
     if ($this->isGranted('ROLE_ADMIN')) {
-        return ['key' => 'value'];
+        return $this->render('detail.html.twig', ['key' => 'value']);
     }

     return new RedirectResponse('/');
 }

When the inferred type is a union, mixed, or comes back from a method call the rule cannot resolve, the classification is a guess. Guessing wrong either drops the render call or wraps a Response in another Response.

Both questions are answerable inside one codebase and not in general. A local custom rule can hardcode the template path convention and the return shapes that actually occur, which is both simpler and safe.

The rule is registered in no set, so it can only be reached by hand-registering it.

Changes

  • TemplateAnnotationToThisRenderRector implements DeprecatedInterface and throws on refactor(), matching the existing deprecation pattern
  • Removes the helper classes the rule was the only consumer of: ThisRenderFactory, TemplateGuesser, BundleClassResolver, ArrayUnionResponseTypeAnalyzer, ReturnTypeDeclarationUpdater, EmptyReturnNodeFinder, AnnotationAnalyzer, AnnotationOrAttributeValueResolver, ArrayFromCompactFactory
  • Removes SymfonyAnnotation::TEMPLATE, unused once the rule stops resolving the annotation
  • Removes the rule test suite and its 37 fixtures

The rule guesses the template name from bundle and controller naming
conventions, and has to classify every return as either template
variables or an already built Response. Both depend on project-specific
conventions, which makes the rewrite risky to run blindly.

Remove the rule internals and the now unused helper classes it was the
only consumer of.
@TomasVotruba TomasVotruba changed the title [Deprecation] Deprecate TemplateAnnotationToThisRenderRector [Deprecation] Deprecate TemplateAnnotationToThisRenderRector as risky, annotation based and better tailored to the project Aug 2, 2026
@TomasVotruba
TomasVotruba merged commit a90bac7 into main Aug 2, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-template-annotation-to-this-render branch August 2, 2026 17:51
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