A wrapper Composer library for running Rector via Docker. This package provides a convenient way to use Rector without requiring PHP or Rector to be installed locally on your system.
This Composer package provides a rector-docker
command that wraps the zoliszabo/rector-docker Docker image, making it easy to run Rector on your PHP projects through a simple command-line interface.
- No local PHP installation required - Run Rector regardless of your system's PHP version
- Always up-to-date - Uses the latest Rector version from the Docker image
- Cross-platform compatibility - Works on any system that supports Docker
- Intelligent terminal detection - Automatically handles interactive vs non-interactive environments
- Simple integration - Drop-in replacement for the standard
rector
command
Install the package globally to use the rector-docker
command from anywhere:
composer global require zoliszabo/rector-docker
Make sure your global Composer bin
directory is in your system's PATH
. You can find the path with:
composer global config bin-dir --absolute
You can also install it as a development dependency in your project:
composer require --dev zoliszabo/rector-docker
Once installed, navigate to your project directory and use rector-docker
exactly like you would use the regular rector
command.
# Process using default rector.php configuration
rector-docker process
# Process your src directory
rector-docker process src
# Show available rules
rector-docker list-rules
# Generate a rector.php configuration file
rector-docker init
# Dry run to see what would be changed
rector-docker process src --dry-run
# Process with a specific configuration file
rector-docker process src --config custom-rector.php
When installed as a project dependency, prefix commands with vendor/bin/
:
# Process using default rector.php configuration
vendor/bin/rector-docker process
# Process your src directory
vendor/bin/rector-docker process src
# Or use composer exec
composer exec rector-docker process src
All arguments and options are passed directly to Rector running inside the Docker container.
The rector-docker
command:
- Detects if it's running in an interactive terminal environment
- Mounts your current working directory to
/app
inside the Docker container - Runs the appropriate
docker run
command with the correct flags - Forwards all your arguments to Rector inside the container
The script automatically detects the environment:
- Interactive terminals: Uses
-it
flags for proper terminal interaction - CI/Scripts: Omits
-it
flags to prevent hanging in non-interactive environments
- Docker installed and running on your system
- Composer for package installation
This package uses the zoliszabo/rector:latest
Docker image, which contains:
- Latest PHP version
- Latest Rector version
- All necessary dependencies
- rector-docker - The underlying Docker image
- Rector - The PHP refactoring tool
MIT License. See LICENSE file for details.
Issues and pull requests are welcome!