Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateAnnotationRector adds template name at the end of Route annotation #2158

Closed
stedekay opened this issue Oct 14, 2019 · 2 comments
Closed
Labels

Comments

@stedekay
Copy link
Contributor

stedekay commented Oct 14, 2019

Subject Details
Rector version v0.5.16
PHP version PHP 7.3.3
Full Command vendor/bin/rector process /src --set framework-extra-bundle-50

Current Behaviour

The template name of the Template annotation gets added to the Route annotation.

1) src/PAPP/UserBundle/Controller/FacilityController.php                                                                              
    ---------- begin diff ----------                                                                                                  
--- Original                                                                                                                          
+++ New                                                                                                                               
@@ -35,8 +35,7 @@                                                                                                                          
}

     /**
-     * @Route("/change", name="facility_change")                                                                                     
-     * @Template("PAPPUserBundle:Facility:facility.html.twig")                                                                       
+     * @Route("/change", name="facility_change")("PAPPUserBundle:Facility:facility.html.twig")
      */
     public function changeFacilityAction(): array
@@ -45,9 +44,9 @@                                                                                                                              
         $facilities = $this->facilityRepository->findFacilities();

-        return [                                                                                                                     
+        return $this->render('PAPPUserBundle:Facility:facility.html.twig', [                                                                      
              'facilities' => $facilities,
-        ];                                                                                                                           
+        ]);                                                                                                                              
 }

     /**
    ----------- end diff -----------                                                                                                  
Applied rectors:

 * Rector\Sensio\Rector\FrameworkExtraBundle\TemplateAnnotationRector

Minimal PHP Code Causing Issue

class FacilityController extends DefaultController
{
    /**
     * @var FacilityRepository
     */
    private $facilityRepository;

    public function __construct(FacilityRepository $facilityRepository)
    {
        $this->facilityRepository= $facilityRepository;
    }

    /**
     * @Route("/change", name="facility_change")
     * @Template("PAPPUserBundle:Facility:facility.html.twig")
     */
    public function changeFacilityAction(): array
    {
        $facilities = $this->facilityRepository->findFacilities();

        return [
            'facilities' => $facilities,
        ];
    }
}

Expected Behaviour

1) src/PAPP/UserBundle/Controller/FacilityController.php                                                                              
    ---------- begin diff ----------                                                                                                  
--- Original                                                                                                                          
+++ New                                                                                                                               
@@ -35,8 +35,7 @@                                                                                                                          
}

     /**
      * @Route("/change", name="facility_change")                                                                                     
-     * @Template("PAPPUserBundle:Facility:facility.html.twig")                                                                       
      */
     public function changeFacilityAction(): array
@@ -45,9 +44,9 @@                                                                                                                              
         $facilities = $this->facilityRepository->findFacilities();

-        return [                                                                                                                     
+        return $this->render('PAPPUserBundle:Facility:facility.html.twig', [                                                                      
              'facilities' => $facilities,
-        ];                                                                                                                           
+        ]);                                                                                                                              
 }

     /**
    ----------- end diff -----------                                                                                                  
Applied rectors:

 * Rector\Sensio\Rector\FrameworkExtraBundle\TemplateAnnotationRector
@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 18, 2019

Hi Stefan,

thanks for the report. I'm looking at it.

TomasVotruba added a commit that referenced this issue Oct 18, 2019
@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 18, 2019

I've added test case and it fails as you say, good 😄

https://github.com/rectorphp/rector/pull/2181/files#diff-a37417d170112374570439d94c834010

TomasVotruba added a commit that referenced this issue Oct 18, 2019
TomasVotruba added a commit that referenced this issue Oct 18, 2019
TomasVotruba added a commit that referenced this issue Apr 25, 2022
rectorphp/rector-src@4981ebe Move FileWithoutNamespaceNodeTraverser outside RectorNodeTraverser (#2158)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants