Search by

adachsoft / csfixer-runner-lib

Arkadiusz Adach

Run PHP-CS-Fixer from PHP and parse its output into structured results.

Package info

gitlab.com/a.adach/csfixer-runner-lib

Issues

pkg:composer/adachsoft/csfixer-runner-lib

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-11 20:14 UTC

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 CommandExecutorInterface implementation from adachsoft/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.