[CodeQuality] Respect typeGuardedClasses and skip closure-only returns in ResponseReturnTypeControllerActionRector#964
Merged
Conversation
…s in ResponseReturnTypeControllerActionRector
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 fixes for
ResponseReturnTypeControllerActionRector.1. Respect
typeGuardedClassesFollow-up to rectorphp/rector-src#8135. The rule wrote return types even into classes the user guarded via
withTypeGuardedClasses(), which is a breaking change for their child classes. Now it bails out throughParentClassMethodTypeOverrideGuard::isTypeGuardedClass().With
->withTypeGuardedClasses([AbstractCustomController::class]):Final classes cannot be extended, so they are still refactored:
final class SomeController extends AbstractCustomController { #[Route] - public function detail() + public function detail(): \Symfony\Component\HttpFoundation\Response { return $this->render('some_template'); } }Controllers outside the guarded tree are untouched by the option:
class SomeController extends AbstractController { #[Route] - public function detail() + public function detail(): \Symfony\Component\HttpFoundation\Response { return $this->render('some_template'); } }2. Skip methods whose only
returnlives in a closurehasReturn()used the unscopedhasInstancesOf(), so a closure body counted as the method's return.isResponseReturnMethod()then saw zero scoped returns and vacuously returnedtrue, producing a bogus type on a method that returns nothing:final class SomeController extends AbstractController { #[Route] - public function detail() + public function detail(): \Symfony\Component\HttpFoundation\RedirectResponse { $callback = function () { return 'hey'; }; $callback(); } }Switched to
hasInstancesOfInFunctionLikeScoped().