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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;

final class SkipEventSubscriberMethod extends AbstractController implements EventSubscriberInterface
{
public function onRequest(RequestEvent $requestEvent): void
{
$controller = $requestEvent->getRequest()->attributes->get('_controller');
}

/**
* @return array<string, string>
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => 'onRequest',
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Rector\Symfony\Tests\CodeQuality\Rector\Class_\ControllerMethodInjectionToConstructorRector\Fixture;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;

final class SkipSessionInterface extends AbstractController
{
#[Route('/some-action', name: 'some_action')]
public function someAction(SessionInterface $session)
{
$session->invalidate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public function refactor(Node $node): ?Node
new ObjectType(SymfonyClass::USER_INTERFACE),
new ObjectType('DateTimeInterface'),
new ObjectType(SymfonyClass::UUID),
// event listener method, not a controller action
new ObjectType(SymfonyClass::EVENT),
// request-scoped, must stay in the action method
new ObjectType(SymfonyClass::SESSION_INTERFACRE),
]
)) {
continue;
Expand Down
2 changes: 2 additions & 0 deletions src/Enum/SymfonyClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final class SymfonyClass

public const string EVENT_DISPATCHER_INTERFACE = 'Symfony\Contracts\EventDispatcher\EventDispatcherInterface';

public const string EVENT = 'Symfony\Contracts\EventDispatcher\Event';

public const string VALIDATOR_INTERFACE = 'Symfony\Component\Validator\Validator\ValidatorInterface';

public const string LOGGER_INTERFACE = 'Psr\Log\LoggerInterface';
Expand Down
Loading