From 2c77cd6f1ad210511d84fd75768b5a1e39a7d382 Mon Sep 17 00:00:00 2001 From: Eike Starkmann Date: Mon, 27 Nov 2023 16:34:06 +0100 Subject: [PATCH] [TASK] add rector Ref:#851 --- composer.json | 1 + rector.php | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 9a51138d..6c981369 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "saschaegerer/phpstan-typo3": "^1.9.1", "seld/jsonlint": "^1.10.0", "squizlabs/php_codesniffer": "^3.7.2", + "ssch/typo3-rector": "^1.3", "symfony/yaml": "^5.3.6 || ^6.2.0", "tomasvotruba/type-coverage": "^0.2.1", "typo3/cms-fluid-styled-content": "^11.5.4 || ^12.4.0", diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..fffdd621 --- /dev/null +++ b/rector.php @@ -0,0 +1,110 @@ +parameters(); + // $parameters->set(Typo3Option::TYPOSCRIPT_INDENT_SIZE, 2); + + $rectorConfig->sets([ + Typo3LevelSetList::UP_TO_TYPO3_11, + // https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ExtensionArchitecture/FileStructure/Configuration/Icons.html + // Typo3SetList::REGISTER_ICONS_TO_ICON, + ]); + + // Register a single rule. Single rules don't load the main config file, therefore the config file needs to be loaded manually. + // $rectorConfig->import(__DIR__ . '/vendor/ssch/typo3-rector/config/config.php'); + // $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v9\v0\InjectAnnotationRector::class); + + // To have a better analysis from phpstan, we teach it here some more things + $rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH); + + // FQN classes are not imported by default. If you don't do it manually after every Rector run, enable it by: + $rectorConfig->importNames(); + + // Disable parallel otherwise non php file processing is not working i.e. typoscript or flexform + $rectorConfig->disableParallel(); + + // this will not import root namespace classes, like \DateTime or \Exception + $rectorConfig->importShortClasses(false); + + // Define your target version which you want to support + $rectorConfig->phpVersion(PhpVersion::PHP_74); + + // If you only want to process one/some TYPO3 extension(s), you can specify its path(s) here. + // If you use the option --config change __DIR__ to getcwd() + // $rectorConfig->paths([ + // __DIR__ . '/packages/acme_demo/', + // ]); + + // When you use rector there are rules that require some more actions like creating UpgradeWizards for outdated TCA types. + // To fully support you we added some warnings. So watch out for them. + + // If you use importNames(), you should consider excluding some TYPO3 files. + $rectorConfig->skip([ + // @see https://github.com/sabbelasichon/typo3-rector/issues/2536 + __DIR__ . '/**/Configuration/ExtensionBuilder/*', + // We skip those directories on purpose as there might be node_modules or similar + // that include typescript which would result in false positive processing + __DIR__ . '/**/Resources/**/node_modules/*', + __DIR__ . '/**/Resources/**/NodeModules/*', + __DIR__ . '/**/Resources/**/BowerComponents/*', + __DIR__ . '/**/Resources/**/bower_components/*', + __DIR__ . '/**/Resources/**/build/*', + __DIR__ . '/vendor/*', + __DIR__ . '/Build/*', + __DIR__ . '/public/*', + __DIR__ . '/.github/*', + __DIR__ . '/.Build/*', + NameImportingPostRector::class => [ + 'ext_localconf.php', + 'ext_tables.php', + 'ClassAliasMap.php', + __DIR__ . '/**/Configuration/*.php', + __DIR__ . '/**/Configuration/**/*.php', + ] + ]); + + // If you have trouble that rector cannot run because some TYPO3 constants are not defined add an additional constants file + // @see https://github.com/sabbelasichon/typo3-rector/blob/main/typo3.constants.php + // @see https://getrector.com/documentation/static-reflection-and-autoload#include-files + // $rectorConfig->bootstrapFiles([ + // __DIR__ . '/typo3.constants.php' + // ]); + + /** + * Useful rule from RectorPHP itself to transform i.e. GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager') + * to GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class) calls. + * But be warned, sometimes it produces false positives (edge cases), so watch out + */ + // $rectorConfig->rule(\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class); + + // Optional non-php file functionalities: + // @see https://github.com/sabbelasichon/typo3-rector/blob/main/docs/beyond_php_file_processors.md + + // Rewrite your extbase persistence class mapping from typoscript into php according to official docs. + // This processor will create a summarized file with all the typoscript rewrites combined into a single file. + /* $rectorConfig->ruleWithConfiguration(\Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v10\v0\ExtbasePersistenceTypoScriptRector::class, [ + \Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v10\v0\ExtbasePersistenceTypoScriptRector::FILENAME => __DIR__ . '/packages/acme_demo/Configuration/Extbase/Persistence/Classes.php', + ]); */ + // Add some general TYPO3 rules + $rectorConfig->rule(ConvertImplicitVariablesToExplicitGlobalsRector::class); + $rectorConfig->ruleWithConfiguration(ExtEmConfRector::class, [ + ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [] + ]); + + // Modernize your TypoScript include statements for files and move from to @import use the FileIncludeToImportStatementVisitor (introduced with TYPO3 9.0) + // $rectorConfig->rule(\Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v9\v0\FileIncludeToImportStatementTypoScriptRector::class); +};