diff --git a/config/v9/typo3-90.php b/config/v9/typo3-90.php index 5cebfe45d..4600db60f 100644 --- a/config/v9/typo3-90.php +++ b/config/v9/typo3-90.php @@ -14,6 +14,7 @@ use Ssch\TYPO3Rector\Rector\v9\v0\InjectAnnotationRector; use Ssch\TYPO3Rector\Rector\v9\v0\MetaTagManagementRector; use Ssch\TYPO3Rector\Rector\v9\v0\MoveRenderArgumentsToInitializeArgumentsMethodRector; +use Ssch\TYPO3Rector\Rector\v9\v0\RefactorBackendUtilityGetPagesTSconfigRector; use Ssch\TYPO3Rector\Rector\v9\v0\RefactorDeprecationLogRector; use Ssch\TYPO3Rector\Rector\v9\v0\RefactorMethodsFromExtensionManagementUtilityRector; use Ssch\TYPO3Rector\Rector\v9\v0\RemoveMethodInitTCARector; @@ -91,4 +92,6 @@ ); $services->set(UseNewComponentIdForPageTreeRector::class); + + $services->set(RefactorBackendUtilityGetPagesTSconfigRector::class); }; diff --git a/src/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfigRector.php b/src/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfigRector.php new file mode 100644 index 000000000..f064c087e --- /dev/null +++ b/src/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfigRector.php @@ -0,0 +1,82 @@ +isMethodStaticCallOrClassMethodObjectType($node, BackendUtility::class)) { + return null; + } + + if (! $this->isName($node->name, 'getPagesTSconfig')) { + return null; + } + + if (! isset($node->args[1], $node->args[2])) { + return null; + } + + $rootLine = $this->getValue($node->args[1]->value); + $returnPartArray = $this->getValue($node->args[2]->value); + + // If a custom non default rootline is given, nothing can be done + if ('null' !== $rootLine) { + return null; + } + + // Just remove the arguments if equals to default ones + if (false === $returnPartArray) { + $node->args = [$node->args[0]]; + + return null; + } + + // Change to method name getRawPagesTSconfig if argument $returnPartArray is true and rootline is null + $node->name = new Identifier('getRawPagesTSconfig'); + $node->args = [$node->args[0]]; + + return null; + } + + /** + * @codeCoverageIgnore + */ + public function getDefinition(): RectorDefinition + { + return new RectorDefinition('Refactor method getPagesTSconfig of class BackendUtility if possible', [ + new CodeSample(<<<'PHP' +use TYPO3\CMS\Backend\Utility\BackendUtility; +$pagesTsConfig = BackendUtility::getPagesTSconfig(1, $rootLine = null, $returnPartArray = true); +PHP + , <<<'PHP' +use TYPO3\CMS\Backend\Utility\BackendUtility; +$pagesTsConfig = BackendUtility::getRawPagesTSconfig(1, $rootLine = null); +PHP + ), + ]); + } +} diff --git a/stubs/Backend/Utility/BackendUtility.php b/stubs/Backend/Utility/BackendUtility.php index 9a985f14a..fc64958a1 100644 --- a/stubs/Backend/Utility/BackendUtility.php +++ b/stubs/Backend/Utility/BackendUtility.php @@ -57,4 +57,13 @@ public static function getPidForModTSconfig($table, $uid, $pid): int { return 1; } + + public static function getPagesTSconfig($id, $rootLine = null, $returnPartArray = false): void + { + } + + public static function getRawPagesTSconfig($id, array $rootLine = null): void + { + + } } diff --git a/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/Fixture/refactor_backend_utility_get_pages_tsconfig.php.inc b/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/Fixture/refactor_backend_utility_get_pages_tsconfig.php.inc new file mode 100644 index 000000000..add153934 --- /dev/null +++ b/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/Fixture/refactor_backend_utility_get_pages_tsconfig.php.inc @@ -0,0 +1,65 @@ +rootline, $returnPartArray); + } +} + +$id = 1; +BackendUtility::getPagesTSconfig($id); +BackendUtility::getPagesTSconfig($id, null, false); +$returnPartArray = true; +BackendUtility::getPagesTSconfig($id, null, $returnPartArray); +BackendUtility::getPagesTSconfig($id, ['rootline'], true); + +?> +----- +rootline, $returnPartArray); + } +} + +$id = 1; +BackendUtility::getPagesTSconfig($id); +BackendUtility::getPagesTSconfig($id); +$returnPartArray = true; +BackendUtility::getRawPagesTSconfig($id); +BackendUtility::getPagesTSconfig($id, ['rootline'], true); + +?> diff --git a/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/RefactorBackendUtilityGetPagesTSconfigRectorTest.php b/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/RefactorBackendUtilityGetPagesTSconfigRectorTest.php new file mode 100644 index 000000000..ea3cdf49c --- /dev/null +++ b/tests/Rector/v9/v0/RefactorBackendUtilityGetPagesTSconfig/RefactorBackendUtilityGetPagesTSconfigRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideDataForTest(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return RefactorBackendUtilityGetPagesTSconfigRector::class; + } +}