From 1f1f7b67023fca371c13f89459bce6b3461bfd82 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Sat, 21 Nov 2020 20:52:38 +0100 Subject: [PATCH] [TASK] Change default caching framework names (#1253) (#1626) * [TASK] Change default caching framework names (#1253) Resolves: #1253 * [TASK] Correct namespace * [TASK] Add ChangeDefaultCachingFrameWorkNamesRector to TYPO3 10.0 config --- config/v10/typo3-100.php | 2 + ...angeDefaultCachingFrameworkNamesRector.php | 75 +++++++++++++++++++ ...DefaultCachingFrameworkNamesRectorTest.php | 31 ++++++++ ...ge_default_caching_framework_names.php.inc | 41 ++++++++++ 4 files changed, 149 insertions(+) create mode 100644 src/Rector/v10/v0/ChangeDefaultCachingFrameworkNamesRector.php create mode 100644 tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/ChangeDefaultCachingFrameworkNamesRectorTest.php create mode 100644 tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/Fixture/change_default_caching_framework_names.php.inc diff --git a/config/v10/typo3-100.php b/config/v10/typo3-100.php index 28dfbe422..78ca39a7d 100644 --- a/config/v10/typo3-100.php +++ b/config/v10/typo3-100.php @@ -4,6 +4,7 @@ use Rector\Renaming\Rector\Namespace_\RenameNamespaceRector; use Ssch\TYPO3Rector\Rector\v10\v0\BackendUtilityGetViewDomainToPageRouterRector; +use Ssch\TYPO3Rector\Rector\v10\v0\ChangeDefaultCachingFrameworkNamesRector; use Ssch\TYPO3Rector\Rector\v10\v0\ConfigurationManagerAddControllerConfigurationMethodRector; use Ssch\TYPO3Rector\Rector\v10\v0\ForceTemplateParsingInTsfeAndTemplateServiceRector; use Ssch\TYPO3Rector\Rector\v10\v0\RefactorIdnaEncodeMethodToNativeFunctionRector; @@ -44,4 +45,5 @@ $services->set(RemoveFormatConstantsEmailFinisherRector::class); $services->set(UseTwoLetterIsoCodeFromSiteLanguageRector::class); $services->set(UseControllerClassesInExtbasePluginsAndModulesRector::class); + $services->set(ChangeDefaultCachingFrameworkNamesRector::class); }; diff --git a/src/Rector/v10/v0/ChangeDefaultCachingFrameworkNamesRector.php b/src/Rector/v10/v0/ChangeDefaultCachingFrameworkNamesRector.php new file mode 100644 index 000000000..70e201a9d --- /dev/null +++ b/src/Rector/v10/v0/ChangeDefaultCachingFrameworkNamesRector.php @@ -0,0 +1,75 @@ +isMethodStaticCallOrClassMethodObjectType($node, CacheManager::class)) { + return null; + } + + if (! $this->isName($node->name, 'getCache')) { + return null; + } + + $argument = $this->getValue($node->args[0]->value); + $node->args[0] = $this->createArg(str_replace('cache_', '', $argument)); + + return null; + } + + /** + * @codeCoverageIgnore + */ + public function getDefinition(): RectorDefinition + { + return new RectorDefinition('Use new default cache names like core instead of cache_core)', [ + new CodeSample(<<<'PHP' +$cacheManager = GeneralUtility::makeInstance(CacheManager::class); +$cacheManager->getCache('cache_core'); +$cacheManager->getCache('cache_hash'); +$cacheManager->getCache('cache_pages'); +$cacheManager->getCache('cache_pagesection'); +$cacheManager->getCache('cache_runtime'); +$cacheManager->getCache('cache_rootline'); +$cacheManager->getCache('cache_imagesizes'); +PHP + , <<<'PHP' +$cacheManager = GeneralUtility::makeInstance(CacheManager::class); +$cacheManager->getCache('core'); +$cacheManager->getCache('hash'); +$cacheManager->getCache('pages'); +$cacheManager->getCache('pagesection'); +$cacheManager->getCache('runtime'); +$cacheManager->getCache('rootline'); +$cacheManager->getCache('imagesizes'); +PHP + ), + ]); + } +} diff --git a/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/ChangeDefaultCachingFrameworkNamesRectorTest.php b/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/ChangeDefaultCachingFrameworkNamesRectorTest.php new file mode 100644 index 000000000..4ceba3e96 --- /dev/null +++ b/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/ChangeDefaultCachingFrameworkNamesRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideDataForTest(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return ChangeDefaultCachingFrameworkNamesRector::class; + } +} diff --git a/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/Fixture/change_default_caching_framework_names.php.inc b/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/Fixture/change_default_caching_framework_names.php.inc new file mode 100644 index 000000000..ae287dbcf --- /dev/null +++ b/tests/Rector/v10/v0/ChangeDefaultCachingFrameworkNames/Fixture/change_default_caching_framework_names.php.inc @@ -0,0 +1,41 @@ +getCache('cache_core'); + $cacheManager->getCache('cache_hash'); + $cacheManager->getCache('cache_pages'); + $cacheManager->getCache('cache_pagesection'); + $cacheManager->getCache('cache_runtime'); + $cacheManager->getCache('cache_rootline'); + $cacheManager->getCache('cache_imagesizes'); + } +} +?> +----- +getCache('core'); + $cacheManager->getCache('hash'); + $cacheManager->getCache('pages'); + $cacheManager->getCache('pagesection'); + $cacheManager->getCache('runtime'); + $cacheManager->getCache('rootline'); + $cacheManager->getCache('imagesizes'); + } +} +?>