Rector is a FLOSS tool that instantly upgrades and refactors the PHP code of any PHP 5.3+ code. Let's try it.
https://github.com/rectorphp/rector
Documentation:Source code:
https://getrectorithub.com/documentationrectorphp/rector
CThis Task contains some attempts, some configurations to be tested (please feel. Feel free to update as you test more):.
```
name=rector.php
<?php== Configuration to add support up to PHP 8.2 ==
declare(strict_types=1);{P7}
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\SetList;
return static function (RectorConfig $rectorConfig): void {
// directories to be touched by Rector
$rectorConfig->paths([
__DIR__ . '/conf',
__DIR__ . '/externals',
__DIR__ . '/resources',
__DIR__ . '/scripts',
__DIR__ . '/src',
__DIR__ . '/support',
__DIR__ . '/webroot',
]);== Configuration to remove very old features < PHP 5.5 ==
// actions to be executed by rector
$rectorConfig->sets( [{P6}
// trying to add support to this PHP version and below (PHP 8.1)
Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81,
] );== Execute locally ==
// trying to set the current (and minimum) PHP version to be adopted as base
// https://getrector.com/documentation/php-version-features
// https://we.phorge.it/book/phorge/article/installation_guide/
$rectorConfig->phpVersion(PhpVersion::PHP_55);Create the `rector.php` file in the root of your repository (copy from the above Pastes).
// trying to respect obsolete Phorge's code styles previous to PHP 5.5
$rectorConfig->skip([
// for some reasons we want long "array()" instead of "[]"...
// https://we.phorge.it/book/contrib/article/php_coding_standards/
Rector\Php54\Rector\Array_\LongArrayToShortArrayRector::class,
]);Then install Rector:
// https://getrector.com/documentation/troubleshooting-parallel
// trying to don't destroy my computer
// defaults: 120, 16, 20
$rectorConfig->parallel( 120, 8, 20 );```
};composer require rector/rector --dev
```
ToThen run it locally:
```
vendor/bin/rector process --debug
```
NOTE: To try on a single file, or a single directory, express its path as a command-line argument.
WARNING: The future of our children is important. Don't try to randomly execute on Phorge/Phabricator! This could melt your CPU; nuke your storage; kill polar bears; implode the poles. kThe planet's temperature will polar bearsincrease by half a degree. Don't think that Greta Thunberg will be happy about this. Try only on >= 20GB of RAM, on an SSD, and with a CPU with more than 12 cores. If you don't have enough resources, steal someone else's computer (for example - steal "the cloud").
IMPORTANT: If your computer was stolen it is not our fault. But, look for it in the garbage can and inspect your storage. You may not be able to recover the CPU, but on the disk maybe some person will have left a shiny copy of Phorge that supports PHP 8.2. Try only on an SSDIn that situation it's surely not our fault.
Online demo:
https://getrector.com/demo
== Running on Arcanist ===
Some errors that maybe should be addressed when tryin to execute `vendor/bin/rector process` in Arcanist:
```
[ERROR] Could not process "arcanist/src/config/option/ArcanistAliasesConfigOption.php" file, due to:
"System error: "Syntax error, unexpected T_STRING, expecting T_VARIABLE6"
Run Rector with "--debug" option and post the report here: https://github.com/rectorphp/rector/issues/new". On line: 54
```Documentation:
For the records line 54 is just the end of the file. There are multiple errors like that.https://getrector.com/documentation