atournayre / rector-auto-upgrade
Composer plugin to auto-upgrade using Rector
Installs: 30
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: ^8.2
- composer-plugin-api: ^2.0
- symfony/console: ^6.0 || ^7.0
- symfony/finder: ^6.0
Requires (Dev)
- composer/composer: ^2.0
- phpunit/phpunit: ^9.0|^10.0
Suggests
- rector/rector: For auto-upgrade Rector rules
README
Automate code migrations related to dependency version upgrades using Rector.
This Composer plugin enables package maintainers to provide versioned Rector sets that are automatically executed when packages are updated.
β¨ Purpose
rector-auto-upgrade
defines a standard for embedding versioned Rector "sets" into PHP packages, allowing automated code migration when users upgrade dependencies.
Each version of a package can provide a Rector set describing necessary changes (e.g., class renaming, method signature updates, deprecations, etc.).
π¦ How It Works
- When
composer update
is executed, - The plugin detects which packages are being updated,
- For each updated package, it looks for a Rector set matching the new version,
- If found, the Rector set is executed to automatically refactor the user's code.
ποΈ Expected Package Structure
Each package providing migration support must include the following structure:
my-package/
βββ rector/
β βββ sets/
β βββ 2.0.0.php
β βββ 2.1.0.php
- Each file name corresponds to a target version of the package.
- The content of each file must return a standard Rector configuration closure.
βοΈ Installation
composer require --dev atournayre/rector-auto-upgrade
β οΈ This plugin must only be used in a development environment.
π Requirements
- PHP >= 8.1
- Rector must be installed in the project.
- Composer version 2.0 or higher.
- Packages must include
rector/sets/{version}.php
files for their upgrades.
π§ͺ Example Usage
- A package
my/package
provides a filerector/sets/2.0.0.php
. - The user updates
my/package
from version1.4.0
to2.0.0
. - The plugin detects this version change, finds the matching Rector set, and runs it.
- The userβs code is automatically updated to comply with
my/package
version2.0.0
.
β Limitations & Recommendations
- This plugin is intended only for local.
- Use version control to review and commit changes after execution.
- Only upgrades to higher versions are currently supported.
π€ Contributing
Feedback and contributions are welcome.
Feel free to open an issue or submit a pull request.