ssch/typo3-rector
Instant upgrades and refactoring for TYPO3 sites and extensions, built on Rector. Apply automated code migrations between TYPO3 versions, remove deprecations, and modernize PHP code with a generated Rector config and CLI workflow (dry-run/process).
Installation Add the package to your project via Composer:
composer require --dev ssch/typo3-rector
Initialize the Rector config:
vendor/bin/typo3-init
This generates a rector.php file in your project root.
First Run (Dry Run) Preview changes before applying them:
vendor/bin/rector process --dry-run
Review the output to ensure the transformations align with your migration goals.
Apply Changes Once satisfied with the preview, run:
vendor/bin/rector process
Commit the changes to version control.
rector.php
Key sections:
return static::configure()
->withPaths([__DIR__.'/Classes', __DIR__.'/Tests'])
->withRules([...]) // Add TYPO3-specific rules here
->withPreparedSets(); // Use predefined sets (e.g., `typo3:code-quality`)
Migrate from TYPO3 v10 to v14:
rector.php to target v14:
->withPreparedSets()
->withSet(Typo3SetList::TYPO3_10_14),
vendor/bin/rector process --dry-run --level=max
PreparedSets to apply all rules for a TYPO3 version upgrade.
->withPreparedSets()
->withSet(Typo3SetList::TYPO3_11_12),
withRules():
->withRules([
MigrateTypoScriptFrontendControllerConfigRector::class,
RemoveTypo3VersionChecksRector::class => [
RemoveTypo3VersionChecksRector::TARGET_VERSION => 14,
],
]),
vendor/bin/rector process --paths=Extensions/MyExtension/Classes
vendor/bin/ecs check src --fix
# .github/workflows/rector.yml
jobs:
rector:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: vendor/bin/rector process --dry-run
--level=max to enforce strict checks in CI.vendor/bin/rector create-rule MyCustomRule
Then register it in rector.php:
->withRules([
\Vendor\MyCustomRule::class,
]),
Classes/ and Tests/ directories:
->withPaths([
__DIR__.'/Classes',
__DIR__.'/Tests/Unit',
]),
typo3-rector for PHP migrations; pair with fractor for Fluid/TypoScript:
composer require --dev andreaswolf/fractor
vendor/bin/fractor process
Global State Changes:
MigrateGLOBALS['TSFE']->fe_user may break if your code relies on global state.@ignore annotations for problematic cases:
/** @ignore Rector\Typo3\Rector\ClassMethod\MigrateFeUserRector */
public function oldMethod() { ... }
False Positives:
GeneralUtility::makeInstance()).->withExcludedPaths([
__DIR__.'/Vendor/LegacyCode',
]),
Coding Standards:
vendor/bin/ecs check src --fix
Use the provided ECS config as a baseline.Performance:
vendor/bin/rector process --parallel
Dry Run with Verbosity:
vendor/bin/rector process --dry-run -vv
This shows why each change is applied.
Rule-Specific Debugging: Disable a rule temporarily:
->withRules([
MigrateTypoScriptFrontendControllerConfigRector::class => false,
]),
Git Integration:
Use git diff to review changes:
git diff --name-only HEAD | xargs vendor/bin/rector process --dry-run
Custom Rule Conditions:
Use ShouldRunCondition to control rule execution:
class MyCustomCondition implements ShouldRunCondition
{
public function shouldRun(): bool
{
return !app()->environment('production');
}
}
Register in rector.php:
->withRuleWithCondition(MyCustomRule::class, new MyCustomCondition()),
Post-Rector Hooks: Chain Rector with other tools (e.g., PHPStan) via a custom script:
# post-rector.sh
vendor/bin/rector process && vendor/bin/phpstan analyse --level=max
TYPO3-Specific Annotations:
Use @var or @method annotations to guide Rector:
/**
* @var \TYPO3\CMS\Core\Utility\GeneralUtility
*/
private $generalUtility;
typo3-init Overrides:
Running vendor/bin/typo3-init again may reset your rector.php. Backup or merge changes manually.
Rector Version Pinning:
Pin ssch/typo3-rector to a specific version in composer.json to avoid unexpected rule changes:
"require-dev": {
"ssch/typo3-rector": "^3.14.0"
}
PHP Version Mismatches:
Ensure your php-parser version matches Rector’s requirements (e.g., PHP 8.1+ for Rector v2.4+).
vendor/bin/rector process --rules=MigrateTypoScriptFrontendControllerConfigRector
git stash before running Rector on large codebases:
git stash && vendor/bin/rector process && git stash pop
typo3:code-quality set:
->withPreparedSets()
->withSet(Typo3SetList::TYPO3_CODE_QUALITY),
How can I help you explore Laravel packages today?