Find the best Rector rule to solve your problem. Searching through 1011 rules.
Found 8 rules:
Replace $this->getDoctrine() and $this->dispatchMessage() calls in AbstractController with direct service use
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
+use Doctrine\Persistence\ManagerRegistry;
final class SomeController extends AbstractController
{
+ public function __construct(
+ private ManagerRegistry $managerRegistry
+ ) {
+ }
+
public function run()
{
- $productRepository = $this->getDoctrine()->getRepository(Product::class);
+ $productRepository = $this->managerRegistry->getRepository(Product::class);
}
}
Simplify use of assertions in WebTestCase
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class SomeTest extends KernelTestCase
{
protected function setUp(): void
{
- $container = self::$container;
+ $container = self::getContainer();
}
}
Change RouteCollectionBuilder to RoutingConfiguratorRector
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel;
-use Symfony\Component\Routing\RouteCollectionBuilder;
+use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
final class ConcreteMicroKernel extends Kernel
{
use MicroKernelTrait;
- protected function configureRoutes(RouteCollectionBuilder $routes)
+ protected function configureRouting(RoutingConfigurator $routes): void
{
- $routes->add('/admin', 'App\Controller\AdminController::dashboard', 'admin_dashboard');
- }
-}
+ $routes->add('admin_dashboard', '/admin')
+ ->controller('App\Controller\AdminController::dashboard')
+ }}
Change Twig template short name to bundle syntax in render calls from controllers
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class BaseController extends Controller
{
function indexAction()
{
- $this->render('appBundle:Landing\Main:index.html.twig');
+ $this->render('@app/Landing/Main/index.html.twig');
}
}
Changes createForm(new FormType), add(new FormType) to ones with "FormType::class"
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
final class SomeController extends Controller
{
public function action()
{
- $form = $this->createForm(new TeamType);
+ $form = $this->createForm(TeamType::class);
}
}
Turns fetching of dependencies via $this->get() to constructor injection in Command and Controller
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
final class SomeController extend Controller
{
+ public function __construct(SomeService $someService)
+ {
+ $this->someService = $someService;
+ }
+
public function someMethod()
{
- // ...
- $this->get('some_service');
+ $this->someService;
}
}
Turns redirect to route to short helper method in Controller in Symfony
-$this->redirect($this->generateUrl("homepage"));
+$this->redirectToRoute("homepage");
Turns fetching of Request via $this->getRequest() to action injection
+use Symfony\Component\HttpFoundation\Request;
+
class SomeController
{
- public function someAction()
+ public function someAction(Request $request)
{
- return $this->getRequest()->getContent();
+ return $request->getContent();
}
}