atournayre / rector-auto-upgrade
Composer plugin to auto-upgrade using Rector
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
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
A Composer plugin that automatically runs Rector upgrades for your installed packages after a composer update
.
Description
This plugin scans your installed packages after running composer update
and checks if they provide Rector upgrade configurations. If found, it offers to automatically apply these upgrades to your codebase, making package version migrations easier.
Installation
Install the package via Composer:
composer require --dev atournayre/rector-auto-upgrade
Requirements
- PHP 8.0 or higher
- Composer 2.0 or higher
- Rector must be installed in your project
How It Works
- After running
composer update
, the plugin activates - It scans all installed packages for Rector upgrade configurations at
vendor/package-name/rector/upgrade/[X.Y.Z]/rector.php
- For each found configuration, it prompts you if you want to run the upgrade
- If you confirm, it creates a temporary configuration file and runs Rector with that configuration
Package Compatibility
For package maintainers who want to make their packages compatible with this plugin, you need to:
- Create a directory structure in your package:
rector/upgrade/[X.Y.Z]
- Add a
rector.php
configuration file in that directory - The plugin will automatically detect this configuration during updates
Example directory structure in your package:
├── src/
├── rector/
│ └── upgrade/
│ └── 2.0.0/
│ └── rector.php
└── composer.json
Configuration Variables
In your Rector configuration file, you can use the following variable:
%currentWorkingDirectory%
- Will be replaced with the absolute path to the user's project root
Example of a Rector configuration file:
<?php declare(strict_types=1); use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ '%currentWorkingDirectory%/src', ]); };
Development Environment Detection
The plugin only runs in development environments. An environment is considered a development environment if:
- The Rector binary is installed
- The
APP_ENV
environment variable is set todev
- The
APP_ENV
environment variable is not set toprod
orproduction