-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [TASK] Change default caching framework names (#1253) Resolves: #1253 * [TASK] Correct namespace * [TASK] Add ChangeDefaultCachingFrameWorkNamesRector to TYPO3 10.0 config
- Loading branch information
Tomas Norre Mikkelsen
authored
Nov 21, 2020
1 parent
fcd4ebc
commit 1f1f7b6
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/Rector/v10/v0/ChangeDefaultCachingFrameworkNamesRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Rector\v10\v0; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Rector\Core\RectorDefinition\CodeSample; | ||
use Rector\Core\RectorDefinition\RectorDefinition; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
|
||
/** | ||
* @see https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/10.0/Deprecation-88366-DefaultCachingFrameworkCacheNamesChanged.html | ||
*/ | ||
class ChangeDefaultCachingFrameworkNamesRector extends AbstractRector | ||
{ | ||
/* | ||
* @return string[] | ||
*/ | ||
public function getNodeTypes(): array | ||
{ | ||
return [MethodCall::class]; | ||
} | ||
|
||
/** | ||
* @param MethodCall $node | ||
*/ | ||
public function refactor(Node $node): ?Node | ||
{ | ||
if (! $this->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 | ||
), | ||
]); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...10/v0/ChangeDefaultCachingFrameworkNames/ChangeDefaultCachingFrameworkNamesRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Ssch\TYPO3Rector\Tests\Rector\v10\v0\ChangeDefaultCachingFrameworkNames; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Ssch\TYPO3Rector\Rector\v10\v0\ChangeDefaultCachingFrameworkNamesRector; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class ChangeDefaultCachingFrameworkNamesRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideDataForTest() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
public function provideDataForTest(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
protected function getRectorClass(): string | ||
{ | ||
return ChangeDefaultCachingFrameworkNamesRector::class; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ChangeDefaultCachingFrameworkNames/Fixture/change_default_caching_framework_names.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
|
||
class ChangeDefaultCachingFrameworkNames | ||
{ | ||
public function method(): void | ||
{ | ||
$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 | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
|
||
class ChangeDefaultCachingFrameworkNames | ||
{ | ||
public function method(): void | ||
{ | ||
$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'); | ||
} | ||
} | ||
?> |