Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Update ssch/typo3-rector to v2 #82

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/src/composer.json.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"saschaegerer/phpstan-typo3": "^1.8",
{% endif %}
{% if features.rector %}
"ssch/typo3-rector": "^1.0",
"ssch/typo3-rector": "^2.0",
{% endif %}
"typo3/coding-standards": "^0.7.1",
"typo3/testing-framework": "{{ packages.typo3_testing_framework }}"
Expand Down
90 changes: 29 additions & 61 deletions templates/src/rector.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,37 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\PostRector\Rector\NameImportingPostRector;
use Rector\ValueObject\PhpVersion;
use Ssch\TYPO3Rector\CodeQuality\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\CodeQuality\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v10\v0\ExtbasePersistenceTypoScriptRector;
use Ssch\TYPO3Rector\FileProcessor\TypoScript\Rector\v9\v0\FileIncludeToImportStatementTypoScriptRector;
use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
Typo3LevelSetList::UP_TO_TYPO3_{{ packages.typo3_cms|split('.')|first }},
LevelSetList::UP_TO_PHP_{{ packages.php|replace({'.': ''}) }},
]);

// In order to have a better analysis from phpstan we teach it here some more things
$rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH);

// Disable parallel otherwise non php file processing is not working i.e. typoscript
$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_{{ packages.php|replace({'.': ''}) }});

// 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([
return RectorConfig::configure()
->withConfiguredRule(ExtEmConfRector::class, [
ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [],
])
->withPaths([
__DIR__ . '/packages/*',
]);

// If you use importNames(), you should consider excluding some TYPO3 files.
$rectorConfig->skip([
])
->withPhpSets(php{{ packages.php|replace({'.': ''}) }}: true)
->withSets([
Typo3LevelSetList::UP_TO_TYPO3_{{ packages.typo3_cms|split('.')|first }},
])
->withPHPStanConfigs([
Typo3Option::PHPSTAN_FOR_RECTOR_PATH,
])
->withPhpVersion(PhpVersion::PHP_{{ packages.php|replace({'.': ''}) }})
->withImportNames(importShortClasses: false)
->withRules([
ConvertImplicitVariablesToExplicitGlobalsRector::class,
])
->withSkip([
// @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',
Expand All @@ -61,21 +43,7 @@ return static function (RectorConfig $rectorConfig): void {
],

// We skip this rector rule as it interferes with TYPO3 coding standards
\Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
]);

// 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(ExtbasePersistenceTypoScriptRector::class, [
ExtbasePersistenceTypoScriptRector::FILENAME => __DIR__ . '/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 <INCLUDE /> to @import use the FileIncludeToImportStatementVisitor (introduced with TYPO3 9.0)
$rectorConfig->rule(FileIncludeToImportStatementTypoScriptRector::class);
};
AddLiteralSeparatorToNumberRector::class,
])
->withoutParallel()
;
Loading