Upgrades a PHP project to a newer PHP version using Rector — the automated refactoring tool. Inspects composer.json, detects the current PHP version, selects safe PHP-level rulesets, updates dependencies conservatively, runs a dry-run first, and produces an upgrade checklist with follow-up manual changes. Activate for phrases like "upgrade my PHP version", "modernize PHP syntax", "migrate to PHP 8.3", "fix PHP 8 deprecations", "set up Rector for PHP upgrade", or any request to automate PHP syntax modernization — even when Rector is not mentioned by name.
75
94%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
You are helping upgrade a PHP project to a newer PHP version using Rector.
Read these files before proposing anything:
composer.json — PHP constraint, dependencies, autoload pathscomposer.lock — actual installed versionsrector.php or rector.php.dist — existing Rector config if presentphpunit.xml* — test framework presencephpstan.neon* — static analysis tooling.php-cs-fixer.php or pint.json — formatter configDetermine:
"php": ">=8.1")Propose a conservative update:
composer require rector/rector --devAlso update the PHP constraint in composer.json:
"require": {
"php": ">=8.3"
}Then check for dependency compatibility:
composer why-not php 8.3Do not aggressively rewrite unrelated packages. Note dependencies that often need attention during PHP upgrades:
rector.phpGenerate bootstrap if none exists:
vendor/bin/rector inituse Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSkip([
__DIR__ . '/vendor',
])
->withSets([
LevelSetList::UP_TO_PHP_83, // adjust to target
]);| Constant | Target |
|---|---|
LevelSetList::UP_TO_PHP_74 | PHP 7.4 |
LevelSetList::UP_TO_PHP_80 | PHP 8.0 |
LevelSetList::UP_TO_PHP_81 | PHP 8.1 |
LevelSetList::UP_TO_PHP_82 | PHP 8.2 |
LevelSetList::UP_TO_PHP_83 | PHP 8.3 |
use Rector\Set\ValueObject\SetList;
->withSets([
LevelSetList::UP_TO_PHP_83,
SetList::CODE_QUALITY, // modernizes patterns
SetList::DEAD_CODE, // removes unused code
SetList::TYPE_DECLARATION, // adds type hints (most invasive)
])->withPhpSets(php83: true)->withSkip([
__DIR__ . '/src/Legacy',
\Rector\Php74\Rector\Property\TypedPropertyRector::class,
\Rector\Php74\Rector\Property\TypedPropertyRector::class => [
__DIR__ . '/src/SpecificFile.php',
],
])Always suggest this order:
# 1. Install Rector
composer require rector/rector --dev
# 2. Dry-run — preview only, no writes
vendor/bin/rector process --dry-run
# 3. Review the diff, adjust rector.php if needed, repeat dry-run
# 4. Apply changes
vendor/bin/rector process
# 5. Format (if pint or php-cs-fixer configured)
vendor/bin/pint
# 6. Static analysis
vendor/bin/phpstan analyse
# 7. Run tests
composer testFor large codebases:
vendor/bin/rector process --parallel
php -d memory_limit=-1 vendor/bin/rector process # if memory errorsCommit after each logical batch:
git add -A && git commit -m "chore: apply Rector PHP 8.3 upgrade rules"Always provide:
rector.php config — ready to usematch expressions, named arguments, nullsafe operator (Rector adds them, but logic changes need review)each(), create_function(), etc.) — Rector flags but can't always fix safelyreadonly properties require intentional adoption, not automaticstrict_types=1 — Rector may add it; review each file where it does| Error | Fix |
|---|---|
Allowed memory size exhausted | php -d memory_limit=-1 vendor/bin/rector process |
| Rector changes nothing | Check withPaths() includes actual source dirs |
Class not found in rector.php | Run composer dump-autoload |
| Rector too slow | Add --parallel flag |
| Wrong PHP version targeted | Use ->withPhpSets(php83: true) explicitly |
| Tests fail after Rector | Identify rule with git bisect or git diff; add to withSkip() |
22c7c54
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.