adachsoft / rector-wrapper-lib
Wrapper library for running Rector with check/fix/patch modes
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/adachsoft/rector-wrapper-lib
Requires
- php: >=8.3
- ext-json: *
- adachsoft/collection: v3.0.0
- adachsoft/command-executor-lib: 2.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.88
- phpstan/phpstan: ^2.1
- phpunit/phpunit: 12.4
- rector/rector: 2.3.2
This package is not auto-updated.
Last update: 2026-01-21 09:55:53 UTC
README
Lightweight wrapper for running Rector in check, fix, and patch modes. Provides a simple Public API (Facade + Factory) and a ready-to-use CLI script.
- Facade methods: check, fix, patch
- Patch formats: Unified and Composer patches
- Limits support (files, hunks, lines, rules)
- CLI:
bin/adachsoft-rector
Requirements
- PHP >= 8.3
- ext-json
- adachsoft/collection
- adachsoft/command-executor-lib
Installation
composer require adachsoft/rector-wrapper-lib
Usage (Library)
Quick start with default factory
use AdachSoft\RectorWrapperLib\PublicApi\RectorWrapperFactory;
use AdachSoft\RectorWrapperLib\PublicApi\Dto\RunRectorRequestDto;
use AdachSoft\RectorWrapperLib\PublicApi\Dto\LimitsDto;
use AdachSoft\RectorWrapperLib\PublicApi\Enum\PatchFormatEnum;
use AdachSoft\RectorWrapperLib\Domain\Collection\PathCollection;
use AdachSoft\RectorWrapperLib\Domain\ValueObject\FilePath;
$facade = RectorWrapperFactory::createDefault();
$request = new RunRectorRequestDto(
paths: PathCollection::fromFilePaths(new FilePath('src')),
configPath: 'rector.php',
dryRun: true,
);
$response = $facade->check($request);
if ($response->status->value === 'OK') {
echo 'Changed files: ' . $response->result->meta->changedFiles . PHP_EOL;
}
Fix mode
$request = new RunRectorRequestDto(
paths: PathCollection::fromFilePaths(new FilePath('src')),
configPath: 'rector.php',
dryRun: false,
);
$response = $facade->fix($request);
Patch mode (Unified)
$response = $facade->patch($request, PatchFormatEnum::UNIFIED);
Patch mode (Composer patches)
$response = $facade->patch($request, PatchFormatEnum::COMPOSER);
Limits
use AdachSoft\RectorWrapperLib\PublicApi\Enum\ErrorUnitEnum;
$limits = new LimitsDto(maxErrors: 10, errorUnit: ErrorUnitEnum::FILES, maxChangedFiles: 20);
$request = new RunRectorRequestDto(
paths: PathCollection::fromFilePaths(new FilePath('src')),
configPath: 'rector.php',
dryRun: true,
limits: $limits,
);
$response = $facade->check($request);
Usage (CLI)
The package registers a binary: bin/adachsoft-rector.
Check
vendor/bin/adachsoft-rector --config=rector.php --path=src --check
Fix
vendor/bin/adachsoft-rector --config=rector.php --path=src --fix
Patch (Unified)
vendor/bin/adachsoft-rector --config=rector.php --path=src --patch=UNIFIED
Patch (Composer)
vendor/bin/adachsoft-rector --config=rector.php --path=src --patch=COMPOSER
Limits and extra args
vendor/bin/adachsoft-rector \
--config=rector.php \
--path=src \
--check \
--limit-max-errors=10 \
--limit-error-unit=FILES \
--limit-max-changed-files=20 \
--extra=--clear-cache \
--extra=--debug=1
Rector configuration
This repository contains a sample rector.php configuration compatible with PHP 8.3 and common quality sets.
Example run using the provided CLI wrapper:
vendor/bin/adachsoft-rector --config=rector.php --path=src --check
If you want to run Rector directly:
vendor/bin/rector process src --config=rector.php --dry-run
License
MIT