diff --git a/packages/Symfony/src/Rector/HttpKernel/GetRequestRector.php b/packages/Symfony/src/Rector/HttpKernel/GetRequestRector.php index 129fe87dad80..9039db41d6ea 100644 --- a/packages/Symfony/src/Rector/HttpKernel/GetRequestRector.php +++ b/packages/Symfony/src/Rector/HttpKernel/GetRequestRector.php @@ -159,6 +159,10 @@ private function isActionWithGetRequestInBody(Node $node): bool // "$this->get('request')" /** @var MethodCall[] $getMethodCalls */ $getMethodCalls = $this->betterNodeFinder->find($node, function (Node $node) { + if (! $node instanceof MethodCall) { + return false; + } + return $this->isName($node, 'get'); }); diff --git a/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct.php.inc b/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct.php.inc deleted file mode 100644 index ed18b218db8a..000000000000 --- a/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct.php.inc +++ /dev/null @@ -1,12 +0,0 @@ -addFlash('success', 'message'); - } -} diff --git a/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct2.php.inc b/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct2.php.inc deleted file mode 100644 index 367ca0063ccc..000000000000 --- a/packages/Symfony/tests/Rector/Controller/AddFlashRector/Correct/correct2.php.inc +++ /dev/null @@ -1,14 +0,0 @@ -getSession()->getFlashBag()->add('success', 'message'); - } -} - -?> ------ diff --git a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Correct/correct.php.inc b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Correct/correct.php.inc deleted file mode 100644 index dc4b3db71a67..000000000000 --- a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Correct/correct.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -getSomething(); - } -} diff --git a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture.php.inc b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture.php.inc index f892280088a0..d50669a9ee38 100644 --- a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture.php.inc +++ b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture.php.inc @@ -11,3 +11,21 @@ class ClassWithNamedService extends SymfonyController $this->getRequest()->getSomething(); } } + +?> +----- +getSomething(); + } +} + +?> diff --git a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture3.php.inc b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture3.php.inc new file mode 100644 index 000000000000..62b8e4270f20 --- /dev/null +++ b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/Fixture/fixture3.php.inc @@ -0,0 +1,120 @@ +createForm(new CaptchaType(), new Captcha()); + $form->add('Enregistrer', 'submit', [ + 'attr' => ['class' => 'btn btn-default'], + ]); + $form->handleRequest($request); + + if ($form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($form->getData()); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'success', + 'Le captcha a bien été ajouté.' + ); + + return $this->redirect($this->generateUrl('captcha')); + } + + return $this->render('App:Captcha:add.html.twig', [ + 'form' => $form->createView(), + ]); + } + + /** + * @Security("has_role('ROLE_ADMIN')") + * + * @param mixed $id + */ + public function editAction($id, Request $request) + { + $em = $this->getDoctrine()->getManager(); + $captcha = $em->getRepository('App:Captcha')->find($id); + if (!$captcha) { + throw new \Exception('Le Captcha n’existe pas.'); + } + $form = $this->createForm(new CaptchaType(), $captcha); + $form->add('Enregistrer', 'submit', [ + 'attr' => ['class' => 'btn btn-default'] + ]); + $form->handleRequest($request); + + if ($form->isValid()) { + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'success', + 'Le captcha a bien été modifié.' + ); + + return $this->redirect($this->generateUrl('captcha')); + } + + return $this->render('App:Captcha:edit.html.twig', [ + 'form' => $form->createView(), + ]); + } + + /** + * @Security("has_role('ROLE_ADMIN')") + */ + public function indexAction() + { + $em = $this->getDoctrine()->getManager(); + + $queryBuilder = $em->createQueryBuilder() + ->select('c') + ->from('App:Captcha', 'c') + ; + + $captchas = $queryBuilder->getQuery()->getResult(); + + return $this->render('App:Captcha:index.html.twig', [ + 'captchas' => $captchas, + ]); + } + + /** + * @Security("has_role('ROLE_ADMIN')") + * + * @param mixed $id + */ + public function removeAction($id) + { + $em = $this->getDoctrine()->getManager(); + $captcha = $em->getRepository('App:Captcha')->find($id); + if (!$captcha) { + throw new \Exception('Le captcha demandé n’existe pas.'); + } + + $em->remove($captcha); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'success', + 'Le captcha a bien été supprimé.' + ); + + return $this->redirect($this->generateUrl('captcha')); + } +} diff --git a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/GetRequestRectorTest.php b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/GetRequestRectorTest.php index 73d5ee6e2892..81a1a5e91a36 100644 --- a/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/GetRequestRectorTest.php +++ b/packages/Symfony/tests/Rector/HttpKernel/GetRequestRector/GetRequestRectorTest.php @@ -9,7 +9,11 @@ final class GetRequestRectorTest extends AbstractRectorTestCase { public function test(): void { - $this->doTestFiles([__DIR__ . '/Fixture/fixture2.php.inc']); + $this->doTestFiles([ + __DIR__ . '/Fixture/fixture.php.inc', + __DIR__ . '/Fixture/fixture2.php.inc', + __DIR__ . '/Fixture/fixture3.php.inc', + ]); } public function getRectorClass(): string diff --git a/tests/Rector/Visibility/ChangeConstantVisibilityRector/ChangeConstantVisibilityRectorTest.php b/tests/Rector/Visibility/ChangeConstantVisibilityRector/ChangeConstantVisibilityRectorTest.php index da4e327954ed..3585fd979f9a 100644 --- a/tests/Rector/Visibility/ChangeConstantVisibilityRector/ChangeConstantVisibilityRectorTest.php +++ b/tests/Rector/Visibility/ChangeConstantVisibilityRector/ChangeConstantVisibilityRectorTest.php @@ -10,7 +10,7 @@ final class ChangeConstantVisibilityRectorTest extends AbstractRectorTestCase { public function test(): void { - $this->doTestFiles([__DIR__ . '/Fixture/fixture2.php.inc']); + $this->doTestFiles([__DIR__ . '/Fixture/fixture.php.inc', __DIR__ . '/Fixture/fixture2.php.inc']); } /** diff --git a/tests/Rector/Visibility/ChangeConstantVisibilityRector/Correct/correct.php.inc b/tests/Rector/Visibility/ChangeConstantVisibilityRector/Correct/correct.php.inc deleted file mode 100644 index bffba9240c2b..000000000000 --- a/tests/Rector/Visibility/ChangeConstantVisibilityRector/Correct/correct.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - +----- +