From 4ef49c9d39a130344056a0049b7a087917d77922 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Tue, 9 Apr 2024 17:19:06 +0200 Subject: [PATCH] [BUGFIX] Do not add return statement if already of type ResponseInterface (#4221) --- ...llerActionsMustReturnResponseInterfaceRector.php | 7 +++++++ .../v2/MigrateGeneralUtilityGPMergedRector.php | 9 +++++---- stubs/TYPO3/CMS/Core/Http/RedirectResponse.php | 13 +++++++++++++ ...roller_actions_return_response_interface.php.inc | 12 ++++++++++++ ...eOnStandardPagesToTCAConfigurationRectorTest.php | 1 - utils/generator/src/ValueObject/TcaRectorType.php | 1 - utils/generator/src/ValueObject/Typo3RectorType.php | 1 - 7 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 stubs/TYPO3/CMS/Core/Http/RedirectResponse.php diff --git a/rules/TYPO311/v0/ExtbaseControllerActionsMustReturnResponseInterfaceRector.php b/rules/TYPO311/v0/ExtbaseControllerActionsMustReturnResponseInterfaceRector.php index 0592173fc..7a7824dcc 100644 --- a/rules/TYPO311/v0/ExtbaseControllerActionsMustReturnResponseInterfaceRector.php +++ b/rules/TYPO311/v0/ExtbaseControllerActionsMustReturnResponseInterfaceRector.php @@ -81,6 +81,13 @@ public function refactor(Node $node): ?Node $returnCallExpression = $node->expr; + if ($returnCallExpression !== null && $this->isObjectType( + $returnCallExpression, + new ObjectType('Psr\Http\Message\ResponseInterface') + )) { + return null; + } + if ($returnCallExpression instanceof FuncCall && $this->isName( $returnCallExpression->name, 'json_encode' diff --git a/rules/TYPO312/v2/MigrateGeneralUtilityGPMergedRector.php b/rules/TYPO312/v2/MigrateGeneralUtilityGPMergedRector.php index 93a5a4534..83e3d218f 100644 --- a/rules/TYPO312/v2/MigrateGeneralUtilityGPMergedRector.php +++ b/rules/TYPO312/v2/MigrateGeneralUtilityGPMergedRector.php @@ -166,10 +166,11 @@ private function generateArrayUtilityMergeRecursiveWithOverruleStatement( } return new Expression( - $this->nodeFactory->createStaticCall('TYPO3\\CMS\\Core\\Utility\\ArrayUtility', 'mergeRecursiveWithOverrule', [ - $this->nodeFactory->createArg($variable), - $this->nodeFactory->createArg($arrayDimFetch), - ]) + $this->nodeFactory->createStaticCall( + 'TYPO3\\CMS\\Core\\Utility\\ArrayUtility', + 'mergeRecursiveWithOverrule', + [$this->nodeFactory->createArg($variable), $this->nodeFactory->createArg($arrayDimFetch)] + ) ); } } diff --git a/stubs/TYPO3/CMS/Core/Http/RedirectResponse.php b/stubs/TYPO3/CMS/Core/Http/RedirectResponse.php new file mode 100644 index 000000000..abe7309e3 --- /dev/null +++ b/stubs/TYPO3/CMS/Core/Http/RedirectResponse.php @@ -0,0 +1,13 @@ + @@ -108,6 +114,7 @@ use TYPO3\CMS\Extbase\Http\ForwardResponse; use Ssch\TYPO3Rector\Tests\Rector\v11\v0\ExtbaseControllerActionsMustReturnResponseInterfaceRector\Source\JsonResponse; use Exception; use Psr\Http\Message\ResponseInterface; +use TYPO3\CMS\Core\Http\RedirectResponse; use TYPO3\CMS\Core\Utility\HttpUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -201,6 +208,11 @@ class MyController extends ActionController { return JsonResponse::fromArray(); } + + public function redirectAction(): ResponseInterface + { + return new RedirectResponse('https://example.com'); + } } ?> diff --git a/tests/Rector/v12/v0/MoveAllowTableOnStandardPagesToTCAConfigurationRector/MoveAllowTableOnStandardPagesToTCAConfigurationRectorTest.php b/tests/Rector/v12/v0/MoveAllowTableOnStandardPagesToTCAConfigurationRector/MoveAllowTableOnStandardPagesToTCAConfigurationRectorTest.php index 737e8c0a7..c55199d8c 100644 --- a/tests/Rector/v12/v0/MoveAllowTableOnStandardPagesToTCAConfigurationRector/MoveAllowTableOnStandardPagesToTCAConfigurationRectorTest.php +++ b/tests/Rector/v12/v0/MoveAllowTableOnStandardPagesToTCAConfigurationRector/MoveAllowTableOnStandardPagesToTCAConfigurationRectorTest.php @@ -4,7 +4,6 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\MoveAllowTableOnStandardPagesToTCAConfigurationRector; -use Nette\Utils\FileSystem; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Ssch\TYPO3Rector\Contract\FilesystemInterface; diff --git a/utils/generator/src/ValueObject/TcaRectorType.php b/utils/generator/src/ValueObject/TcaRectorType.php index eadb1e114..212c52b35 100644 --- a/utils/generator/src/ValueObject/TcaRectorType.php +++ b/utils/generator/src/ValueObject/TcaRectorType.php @@ -39,6 +39,5 @@ protected function refactorColumn(\PhpParser\Node\Expr $columnName, \PhpParser\N $this->hasAstBeenChanged = true; } EOF; - } } diff --git a/utils/generator/src/ValueObject/Typo3RectorType.php b/utils/generator/src/ValueObject/Typo3RectorType.php index adb93401b..1980f8ed1 100644 --- a/utils/generator/src/ValueObject/Typo3RectorType.php +++ b/utils/generator/src/ValueObject/Typo3RectorType.php @@ -43,6 +43,5 @@ public function refactor(\PhpParser\Node $node): ?\PhpParser\Node return $node; } EOF; - } }