Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Make rector configurable #3217

Merged
merged 1 commit into from
Nov 20, 2022
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
4 changes: 3 additions & 1 deletion config/v11/typo3-110.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
$rectorConfig->rule(UniqueListFromStringUtilityRector::class);
$rectorConfig->rule(GetClickMenuOnIconTagParametersRector::class);
$rectorConfig->rule(RemoveAddQueryStringMethodRector::class);
$rectorConfig->rule(ExtbaseControllerActionsMustReturnResponseInterfaceRector::class);
$rectorConfig->ruleWithConfiguration(ExtbaseControllerActionsMustReturnResponseInterfaceRector::class, [
ExtbaseControllerActionsMustReturnResponseInterfaceRector::REDIRECT_METHODS => ['redirect', 'redirectToUri'],
]);
$rectorConfig->rule(SubstituteConstantsModeAndRequestTypeRector::class);
$rectorConfig->rule(RemoveLanguageModeMethodsFromTypo3QuerySettingsRector::class);
$rectorConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use PHPStan\Type\ObjectType;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/11.0/Deprecation-92784-ExtbaseControllerActionsMustReturnResponseInterface.html
*
* @see \Ssch\TYPO3Rector\Tests\Rector\v11\v0\ExtbaseControllerActionsMustReturnResponseInterfaceRector\ExtbaseControllerActionsMustReturnResponseInterfaceRectorTest
*/
final class ExtbaseControllerActionsMustReturnResponseInterfaceRector extends AbstractRector
final class ExtbaseControllerActionsMustReturnResponseInterfaceRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
*/
public const REDIRECT_METHODS = 'redirect_methods';

/**
* @var string
*/
Expand All @@ -36,6 +43,11 @@ final class ExtbaseControllerActionsMustReturnResponseInterfaceRector extends Ab
*/
private const HTML_RESPONSE = 'htmlResponse';

/**
* @var array<int, string>
*/
private array $redirectMethods = ['redirect', 'redirectToUri'];

/**
* @return array<class-string<Node>>
*/
Expand Down Expand Up @@ -137,6 +149,18 @@ public function someAction(): ResponseInterface
]);
}

/**
* @param mixed[] $configuration
*/
public function configure(array $configuration): void
{
$redirectMethods = $configuration[self::REDIRECT_METHODS] ?? $configuration;
Assert::isArray($redirectMethods);
Assert::allString($redirectMethods);

$this->redirectMethods = array_unique(array_merge($redirectMethods, $this->redirectMethods));
}

private function shouldSkip(ClassMethod $classMethod): bool
{
if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
Expand Down Expand Up @@ -209,7 +233,7 @@ private function hasRedirectCall(ClassMethod $classMethod): bool
return false;
}

return $this->isNames($node->name, ['redirect', 'redirectToUri']);
return $this->isNames($node->name, $this->redirectMethods);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ class MyController extends ActionController
{
$this->redirectToUri('foo');
}

public function additionalRedirectMethodToSkiAction()
{
$this->additionalRedirectMethod();
}

private function additionalRedirectMethod()
{

}
}

?>
Expand Down Expand Up @@ -159,6 +169,16 @@ class MyController extends ActionController
{
$this->redirectToUri('foo');
}

public function additionalRedirectMethodToSkiAction()
{
$this->additionalRedirectMethod();
}

private function additionalRedirectMethod()
{

}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../config/config_test.php');
$rectorConfig->rule(ForwardResponseInsteadOfForwardMethodRector::class);
$rectorConfig->rule(ExtbaseControllerActionsMustReturnResponseInterfaceRector::class);
$rectorConfig->ruleWithConfiguration(ExtbaseControllerActionsMustReturnResponseInterfaceRector::class, [
ExtbaseControllerActionsMustReturnResponseInterfaceRector::REDIRECT_METHODS => [
'redirect',
'redirectToUri',
'additionalRedirectMethod',
],
]);
};