Skip to content

Commit

Permalink
[BUGFIX] Do not add return statement if already of type ResponseInter…
Browse files Browse the repository at this point in the history
…face (#4221)
  • Loading branch information
sabbelasichon committed Apr 9, 2024
1 parent ce3e9ab commit 4ef49c9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
Expand Up @@ -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'
Expand Down
9 changes: 5 additions & 4 deletions rules/TYPO312/v2/MigrateGeneralUtilityGPMergedRector.php
Expand Up @@ -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)]
)
);
}
}
13 changes: 13 additions & 0 deletions stubs/TYPO3/CMS/Core/Http/RedirectResponse.php
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace TYPO3\CMS\Core\Http;

if (class_exists('TYPO3\CMS\Core\Http\RedirectResponse')) {
return;
}

final class RedirectResponse extends Response
{

}
Expand Up @@ -5,6 +5,7 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v11\v0\ExtbaseControllerActionsMustRetur
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;

Expand Down Expand Up @@ -96,6 +97,11 @@ class MyController extends ActionController
{
return JsonResponse::fromArray();
}

public function redirectAction()
{
return new RedirectResponse('https://example.com');
}
}

?>
Expand All @@ -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;

Expand Down Expand Up @@ -201,6 +208,11 @@ class MyController extends ActionController
{
return JsonResponse::fromArray();
}

public function redirectAction(): ResponseInterface
{
return new RedirectResponse('https://example.com');
}
}

?>
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion utils/generator/src/ValueObject/TcaRectorType.php
Expand Up @@ -39,6 +39,5 @@ protected function refactorColumn(\PhpParser\Node\Expr $columnName, \PhpParser\N
$this->hasAstBeenChanged = true;
}
EOF;

}
}
1 change: 0 additions & 1 deletion utils/generator/src/ValueObject/Typo3RectorType.php
Expand Up @@ -43,6 +43,5 @@ public function refactor(\PhpParser\Node $node): ?\PhpParser\Node
return $node;
}
EOF;

}
}

0 comments on commit 4ef49c9

Please sign in to comment.