How to Upgrade TYPO3 extensions using rector
Rector is a special tool that analyzes, refactors and upgrades the PHP code of the extension. It can automatically upgrade the codes from one version of PHP to the newer version. It can also refactor the codes and keep the code quality high.
Installation
I will install rector on the system where TYPO3 is installed in composer mode. If you are not using a composer mode, then follow the steps outlined here..
Go to the root page of TYPO3 installation where the composer.json
file is situated and run the following command
composer require --dev rector/rector
Running
To run rector, you first have to create a configuration file. To create it, run the following.
vendor/bin/rector init --template-type=typo3
A new file named rector.php
is created in the same folder. Have a look at the configuration file and change/modify as necessary. For this tutorial, I will change Typo3LevelSetList::UP_TO_TYPO3_11
to Typo3LevelSetList::UP_TO_TYPO3_10
and set the following to true
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
Now you can run rector with the following command.
vendor/bin/rector process packages/my_custom_extension --dry-run
Note: Once everything seems okay you can remove --dry-run and run it to apply the changes