Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/Symfony/src/Rector/HttpKernel/GetRequestRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ class ClassWithNamedService extends SymfonyController
$this->getRequest()->getSomething();
}
}

?>
-----
<?php declare (strict_types=1);

namespace Rector\Symfony\Tests\Rector\HttpKernel\GetRequestRector\Fixture;

use Rector\Symfony\Tests\Rector\Source\SymfonyController;

class ClassWithNamedService extends SymfonyController
{
public function someAction(\Symfony\Component\HttpFoundation\Request $request)
{
$request->getSomething();
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace Rector\Symfony\Tests\Rector\Controller\AddFlashRector\Fixture;

use Rector\Symfony\Tests\Rector\Source\SymfonyController;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Captcha;
use App\Form\CaptchaType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;

class CaptchaController extends SymfonyController
{
/**
* @Security("has_role('ROLE_ADMIN')")
*/
public function addAction(Request $request)
{
get('request');

$form = $this->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'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@ class ClassWithInvalidConstants extends ParentObject
public const TO_BE_PROTECTED_CONSTANT = 2;
protected const TO_BE_PRIVATE_CONSTANT = 3;
}

?>
-----
<?php declare(strict_types=1);

namespace Rector\Tests\Rector\Visibility\ChangePropertyVisibilityRector\Source;

use Rector\Tests\Rector\Visibility\ChangeConstantVisibilityRector\Source\ParentObject;

class ClassWithInvalidConstants extends ParentObject
{
public const TO_BE_PUBLIC_CONSTANT = 1;
protected const TO_BE_PROTECTED_CONSTANT = 2;
private const TO_BE_PRIVATE_CONSTANT = 3;
}

?>