Skip to content

Commit e22fc40

Browse files
committed
Add Rector integration for automated PHP code refactoring and downgrading
- Added `rector/rector` as a development dependency for code upgrades and compatibility adjustments. - Configured a new `rector` script in `composer.json` with a custom PHP 7.4 downgrade rule set. - Introduced `toPhp7.4.php` configuration file to handle downgrades, including typed properties and union types.
1 parent 2186fb1 commit e22fc40

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"pestphp/pest": "^v3.8.4",
1212
"pestphp/pest-plugin-type-coverage": "^v3.6",
1313
"phpunit/phpunit": "^11.5",
14+
"rector/rector": "^2.2",
1415
"vimeo/psalm": "^6.13.1"
1516
},
1617
"autoload": {
@@ -51,6 +52,9 @@
5152
"@mutate",
5253
"echo '\\n\\n\\033[1;32mPre-commit checks passed!\\033[0m\\n'"
5354
],
55+
"rector": [
56+
"./vendor/bin/rector process --config rector/toPhp7.php"
57+
],
5458
"test": [
5559
"./vendor/bin/pest"
5660
],

composer.lock

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector/toPhp7.4.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\DowngradeLevelSetList;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
// We will process code in this specific directory during CI
10+
$rectorConfig->paths([
11+
__DIR__,
12+
]);
13+
14+
// Downgrade rules to make code compatible with PHP 7.2
15+
// This handles readonly classes, typed properties, union types, etc.
16+
$rectorConfig->sets([
17+
DowngradeLevelSetList::DOWN_TO_PHP_74,
18+
]);
19+
};

0 commit comments

Comments
 (0)