[CodeQuality] Skip type-guarded classes + unique autowire method name in ControllerMethodInjectionToConstructorRector - #1007
Merged
Conversation
…oConstructorRector
… unique under inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes to
ControllerMethodInjectionToConstructorRector.1. Skip
->withTypeGuardedClasses([])Removing action method params changes the method signature. If the controller is - or extends - a class listed in
->withTypeGuardedClasses([]), that is a breaking change for its child classes, so the rule leaves such classes untouched. Same guard asResponseReturnTypeControllerActionRectoralready uses; final classes are never guarded, as they cannot be extended.class SomeController extends AbstractCustomController { - public function someAction(LoggerInterface $logger) + public function __construct(private readonly LoggerInterface $logger) + { + } + + public function someAction() { - $logger->log('level', 'value'); + $this->logger->log('level', 'value'); } }With
AbstractCustomControllertype-guarded, the change above is skipped. Non-guarded controllers still change as before.2.
autowire<ShortClassName>()method nameThe added
#[Required]method is now named after the class, so it never collides with anautowire()in a parent or sibling class. Replaces the previousautowire()/autowireServices()fallback pair.final class SomeController extends SomeParentControllerWithConstructor { + private SomeService $someService; + #[Route('/some-path', name: 'some_name')] - public function someAction(SomeService $someService) + public function someAction() { - $data = $someService->getData(); + $data = $this->someService->getData(); } + + #[Required] + public function autowireSomeController(SomeService $someService): void + { + $this->someService = $someService; + } }