Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F266649
Rector.php configuration to support PHP 8.2 on Arcanist and Phorge (+bash script in comments)
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Authored By
valerio.bozzolan
Mar 6 2023, 07:18
2023-03-06 07:18:46 (UTC+0)
Size
3 KB
Referenced Files
None
Subscribers
None
Rector.php configuration to support PHP 8.2 on Arcanist and Phorge (+bash script in comments)
View Options
<?php
/**
* Rector.php configuration to remove very legacy PHP < 5.5 stuff from
* Phorge/Phabricator and Arcanist.
*
* Author: (2023) Valerio Bozzolan and contributors
* License: this specific configuration file is not elegible for copyright
* since it's just a configuration
* so I release it under CC0 public domain.
* Task: https://we.phorge.it/T15145
* Source: https://we.phorge.it/P6
*/
declare(strict_types=1);
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 {
// shared directories to be touched by Rector
// these paths exist in both Arcanist and Phorge
$paths = [
__DIR__ . '/bin',
__DIR__ . '/externals',
__DIR__ . '/resources',
__DIR__ . '/scripts',
__DIR__ . '/src',
__DIR__ . '/support',
];
// rare directories to be touched by Rector
// these paths are probably defined in only Arcanist, or only Phorge
$phaths_rare = [
__DIR__ . '/conf',
__DIR__ . '/webroot',
];
// ignore unexisting paths, add existing paths
foreach( $phaths_rare as $path ) {
if( file_exists( $path ) ) {
$paths[] = $path;
}
}
// process just these paths
$rectorConfig->paths( $paths );
// ignore various test cases at the moment
$rectorConfig->skip( [
__DIR__ . '/src/__tests__/' . '**',
__DIR__ . '/src/*/__tests__/' . '**',
] );
// 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);
// // trying to add support to this PHP version and below (PHP 8.2)
// $rectorConfig->sets( [
// Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82,
// ] );
// trying to remove very old features from old PHP versions (older than PHP 5.5)
// NOTE: I've found these rules by try-catch using UP_TO_PHP_82 first and then
// looking to the proposed changes. So these are probably the minimal changes.
$rectorConfig->rule(Rector\Php53\Rector\FuncCall\DirNameFileConstantToDirConstantRector::class);
$rectorConfig->rule(Rector\Php53\Rector\Ternary\TernaryToElvisRector::class);
$rectorConfig->rule(Rector\Php55\Rector\Class_\ClassConstantToSelfClassRector::class);
// // 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,
//
// // avoid to add the PHPDOC "* @return never" since it can be confusing
// Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector::class,
// ]);
// tried to drop the () function that just returns the first argument
// so I tried just renaming this function to an empty space
// so it should do
// - id( new Asd() )
// + ( new Asd() )
// but this is not supported in Rector since it throws an exception
// $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
// 'id' => '',
// ]);
// So it was implemented in this way:
// find . -name "*.php" ! -name rector.php -exec sed -E -i 's/([ =.+,-\)])id\(/\1(/g' {} +
// trying to don't destroy my computer that does not have 16 cores but 12
// defaults:
// time: 120
// cores: 16
// jobSize: 20
// https://getrector.com/documentation/troubleshooting-parallel
$rectorConfig->parallel( 120, 12, 20 );
};
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
175433
Default Alt Text
Rector.php configuration to support PHP 8.2 on Arcanist and Phorge (+bash script in comments) (3 KB)
Attached To
Mode
P7 Rector.php configuration to support PHP 8.2 on Arcanist and Phorge (+bash script in comments)
Attached
Detach File
Event Timeline
Log In to Comment