From e9573747df0744abe783b3b6b5290929b7c18288 Mon Sep 17 00:00:00 2001 From: Sebastian Schreiber Date: Sun, 21 Aug 2022 22:19:33 +0200 Subject: [PATCH] TASK: Add rector configuration Resolves: #3105 --- config/v12/typo3-120.php | 107 +++++++++++++++++- .../CMS/Core/Messaging/AbstractMessage.php | 22 ++++ .../TYPO3/CMS/Core/Messaging/FlashMessage.php | 14 +++ .../Core/Type/ContextualFeedbackSeverity.php | 15 +++ stubs/TYPO3/CMS/Reports/Status.php | 29 +++++ .../Fixture/fixture.php.inc | 44 +++++++ ...SeveritiesFlashMessageAndReportsRector.php | 34 ++++++ .../config/configured_rule.php | 12 ++ 8 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 stubs/TYPO3/CMS/Core/Messaging/AbstractMessage.php create mode 100644 stubs/TYPO3/CMS/Core/Messaging/FlashMessage.php create mode 100644 stubs/TYPO3/CMS/Core/Type/ContextualFeedbackSeverity.php create mode 100644 stubs/TYPO3/CMS/Reports/Status.php create mode 100644 tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/Fixture/fixture.php.inc create mode 100644 tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/ReplaceSeveritiesFlashMessageAndReportsRector.php create mode 100644 tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/config/configured_rule.php diff --git a/config/v12/typo3-120.php b/config/v12/typo3-120.php index 432878ad8..134e55b61 100644 --- a/config/v12/typo3-120.php +++ b/config/v12/typo3-120.php @@ -3,6 +3,9 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector; +use Rector\Renaming\ValueObject\RenameClassAndConstFetch; +use Rector\Renaming\ValueObject\RenameClassConstFetch; use Ssch\TYPO3Rector\FileProcessor\Resources\Files\Rector\v12\v0\RenameExtTypoScriptFilesFileRector; use Ssch\TYPO3Rector\Rector\Migrations\RenameClassMapAliasRector; use Ssch\TYPO3Rector\Rector\v12\v0\ReplacePreviewUrlMethodRector; @@ -20,13 +23,14 @@ use Ssch\TYPO3Rector\Rector\v12\v0\typo3\ReplaceTSFEWithContextMethodsRector; use Ssch\TYPO3Rector\Rector\v12\v0\typo3\SubstituteCompositeExpressionAddMethodsRector; use Ssch\TYPO3Rector\Rector\v12\v0\typo3\UseCompositeExpressionStaticMethodsRector; +use TYPO3\CMS\Core\Messaging\AbstractMessage; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->import(__DIR__ . '/../config.php'); + $rectorConfig->import(__DIR__.'/../config.php'); $rectorConfig->rule(RenameExtTypoScriptFilesFileRector::class); $rectorConfig->ruleWithConfiguration(RenameClassMapAliasRector::class, [ - __DIR__ . '/../../Migrations/TYPO3/12.0/typo3/sysext/backend/Migrations/Code/ClassAliasMap.php', - __DIR__ . '/../../Migrations/TYPO3/12.0/typo3/sysext/frontend/Migrations/Code/ClassAliasMap.php', + __DIR__.'/../../Migrations/TYPO3/12.0/typo3/sysext/backend/Migrations/Code/ClassAliasMap.php', + __DIR__.'/../../Migrations/TYPO3/12.0/typo3/sysext/frontend/Migrations/Code/ClassAliasMap.php', ]); $rectorConfig->rule(ReplacePreviewUrlMethodRector::class); $rectorConfig->rule(AddMethodToWidgetInterfaceClassesRector::class); @@ -43,4 +47,101 @@ $rectorConfig->rule(ReplaceTSFEWithContextMethodsRector::class); $rectorConfig->rule(SubstituteCompositeExpressionAddMethodsRector::class); $rectorConfig->rule(UseCompositeExpressionStaticMethodsRector::class); + + # https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/12.0/Deprecation-97787-SeveritiesOfFlashMessagesAndReportsDeprecated.html + $rectorConfig->ruleWithConfiguration( + RenameClassConstFetchRector::class, + [ + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\AbstractMessage', + 'NOTICE', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'NOTICE' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\AbstractMessage', + 'INFO', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'INFO' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\AbstractMessage', + 'OK', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'OK' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\AbstractMessage', + 'WARNING', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'WARNING' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\AbstractMessage', + 'ERROR', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'ERROR' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\FlashMessage', + 'NOTICE', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'NOTICE' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\FlashMessage', + 'INFO', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'INFO' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\FlashMessage', + 'OK', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'OK' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\FlashMessage', + 'WARNING', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'WARNING' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Core\Messaging\FlashMessage', + 'ERROR', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'ERROR' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Reports\Status', + 'NOTICE', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'NOTICE' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Reports\Status', + 'INFO', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'INFO' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Reports\Status', + 'OK', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'OK' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Reports\Status', + 'WARNING', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'WARNING' + ), + new RenameClassAndConstFetch( + 'TYPO3\CMS\Reports\Status', + 'ERROR', + 'TYPO3\CMS\Core\Type\ContextualFeedbackSeverity', + 'ERROR' + ), + ] + ); }; diff --git a/stubs/TYPO3/CMS/Core/Messaging/AbstractMessage.php b/stubs/TYPO3/CMS/Core/Messaging/AbstractMessage.php new file mode 100644 index 000000000..dc7271393 --- /dev/null +++ b/stubs/TYPO3/CMS/Core/Messaging/AbstractMessage.php @@ -0,0 +1,22 @@ +severity = $severity; + } + + public function getSeverity(): int + { + return $this->severity; + } +} diff --git a/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/Fixture/fixture.php.inc b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/Fixture/fixture.php.inc new file mode 100644 index 000000000..5d9770b48 --- /dev/null +++ b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/Fixture/fixture.php.inc @@ -0,0 +1,44 @@ +setSeverity(FlashMessage::NOTICE); +$flashMessage->setSeverity(FlashMessage::ERROR); +$flashMessage->setSeverity(FlashMessage::INFO); +$flashMessage->setSeverity(FlashMessage::OK); +$flashMessage->setSeverity(FlashMessage::WARNING); + +$statusNotice = new Status(Status::NOTICE); +$statusInfo = new Status(Status::INFO); +$statusWarning = new Status(Status::WARNING); +$statusOk = new Status(Status::OK); +$statusError = new Status(Status::ERROR); + +?> +----- +setSeverity(ContextualFeedbackSeverity::NOTICE); +$flashMessage->setSeverity(ContextualFeedbackSeverity::ERROR); +$flashMessage->setSeverity(ContextualFeedbackSeverity::INFO); +$flashMessage->setSeverity(ContextualFeedbackSeverity::OK); +$flashMessage->setSeverity(ContextualFeedbackSeverity::WARNING); + +$statusNotice = new Status(ContextualFeedbackSeverity::NOTICE); +$statusInfo = new Status(ContextualFeedbackSeverity::INFO); +$statusWarning = new Status(ContextualFeedbackSeverity::WARNING); +$statusOk = new Status(ContextualFeedbackSeverity::OK); +$statusError = new Status(ContextualFeedbackSeverity::ERROR); + +?> diff --git a/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/ReplaceSeveritiesFlashMessageAndReportsRector.php b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/ReplaceSeveritiesFlashMessageAndReportsRector.php new file mode 100644 index 000000000..fbd960af9 --- /dev/null +++ b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/ReplaceSeveritiesFlashMessageAndReportsRector.php @@ -0,0 +1,34 @@ +doTestFileInfo($fileInfo); + } + + /** + * @return Iterator + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/config/configured_rule.php b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/config/configured_rule.php new file mode 100644 index 000000000..7a928a706 --- /dev/null +++ b/tests/Rector/v12/v0/typo3/ReplaceSeveritiesFlashMessageAndReportsRector/config/configured_rule.php @@ -0,0 +1,12 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->import(__DIR__ . '/../../../../../../../config/v12/typo3-120.php'); +};