atournayre/rector-auto-upgrade
Composer plugin to auto-upgrade using Rector
Maintainers
Package info
github.com/atournayre/rector-auto-upgrade
Type:composer-plugin
pkg:composer/atournayre/rector-auto-upgrade
Requires
- php: >=8.2.22
- composer-plugin-api: ^2.0
- symfony/process: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- composer/composer: ^2.0
- phpunit/phpunit: ^9.0|^10.0
Suggests
- rector/rector: For auto-upgrade Rector rules
Provides
None
Conflicts
None
Replaces
None
MIT 4f47f8c01780c73ac6dcaa0927aacf6e80677f1e
- Aurelien Tournayre <aurelien.tournayre.woop@gmail.com>
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 updateis 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}.phpfiles for their upgrades.
π§ͺ Example Usage
- A package
my/packageprovides a filerector/sets/2.0.0.php. - The user updates
my/packagefrom version1.4.0to2.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/packageversion2.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.
