adachsoft / csfixer-runner-lib
Run PHP-CS-Fixer from PHP and parse its output into structured results.
v0.1.0
2026-11-11 20:14 UTC
Requires
- php: >=8.3
- adachsoft/collection: ^3.0
- adachsoft/command-executor-lib: ^2.0
- adachsoft/normalized-safe-path: ^0.1
Requires (Dev)
- adachsoft/php-code-style: ^0.7.2
- friendsofphp/php-cs-fixer: ^3.89
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
- rector/rector: ^2.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 19:15:00 UTC
README
A PHP library for invoking PHP-CS-Fixer through a command executor and converting its output into typed result objects. It supports dry-run checks and automatic fixes, configurable timeouts, safe target-path normalization, and structured per-file issue details.
Features
- Run PHP-CS-Fixer against a file or directory.
- Choose between dry-run mode and applying fixes.
- Configure the project base path, fixer executable, and timeout.
- Receive the exit code, standard output and error, success status, and parsed file issues.
Requirements
- PHP 8.3 or later.
- PHP-CS-Fixer installed in the target project (by default at
vendor/bin/php-cs-fixer). - A
CommandExecutorInterfaceimplementation fromadachsoft/command-executor-lib.
Installation
composer require adachsoft/csfixer-runner-lib
Install PHP-CS-Fixer in the project that will be checked if it is not already available:
composer require --dev friendsofphp/php-cs-fixer
Basic usage
use AdachSoft\CsFixerRunnerLib\Config\CsFixerRunnerConfigDto;
use AdachSoft\CsFixerRunnerLib\CsFixerRunnerFactory;
use AdachSoft\CsFixerRunnerLib\Dto\RunCsFixerRequestDto;
// Provide an instance implementing CommandExecutorInterface.
$commandExecutor = $yourCommandExecutor;
$config = new CsFixerRunnerConfigDto(
basePath: getcwd(),
phpCsFixerPath: 'vendor/bin/php-cs-fixer',
defaultTimeout: 300,
);
$runner = CsFixerRunnerFactory::create($config, $commandExecutor);
$result = $runner->run(new RunCsFixerRequestDto(path: 'src', fix: false));
if (!$result->success) {
foreach ($result->fileIssues->all() as $issue) {
printf("%s: %s\n", $issue->file, implode(', ', $issue->appliedFixers));
}
}
fix defaults to false, which runs PHP-CS-Fixer in dry-run mode and includes a diff. Set it to true to apply fixes. See the usage example for result handling and configuration details.