adachsoft/cs-fixer-tool

AI tool-call compatible php-cs-fixer runner with safe path normalization and command executor integration.

Maintainers

Package info

gitlab.com/a.adach/cs-fixer-tool

Issues

pkg:composer/adachsoft/cs-fixer-tool

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.0 2026-03-31 13:39 UTC

This package is auto-updated.

Last update: 2026-03-31 11:40:01 UTC


README

AI tool-call compatible php-cs-fixer runner for PHP code style checking and fixing. It integrates with the adachsoft/ai-tool-call SPI, uses normalized safe paths to protect against path traversal, and executes commands via adachsoft/command-executor-lib.

Installation

composer require adachsoft/cs-fixer-tool

Requirements

  • PHP >= 8.2
  • adachsoft/ai-tool-call >= 2.0.1
  • adachsoft/command-executor-lib >= 2.0.0
  • adachsoft/normalized-safe-path >= 0.1.0
  • php-cs-fixer available in your environment (typically vendor/bin/php-cs-fixer)

Integration with AiToolCall

Register the CS Fixer tool factory in your AiToolCallFacade builder:

use Adachsoft\CsFixerTool\Tool\CsFixerToolFactory;
use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;

$builder->registerToolFactory(new CsFixerToolFactory(), new ConfigMap([
    'base_path' => '/var/www/project',
    'php_cs_fixer_path' => 'vendor/bin/php-cs-fixer',
    'default_timeout' => 300,             // optional, default: 300 seconds
    'max_timeout' => 600,                 // optional, default: 600 seconds (upper bound for per-call timeouts)
    'max_output_length' => 10000,         // optional, default: 10000 chars
    'sanitize_base_path' => true,         // optional, default: true
    'use_unsupported_php_version_flag' => true, // optional, default: true (use --allow-unsupported-php-version=yes instead of PHP_CS_FIXER_IGNORE_ENV)
]));

base_path defines the root directory for all tool operations. All user-provided paths are resolved relative to this base and validated using normalized safe paths.

If use_unsupported_php_version_flag is:

  • true (default)
    • php-cs-fixer is executed with --allow-unsupported-php-version=yes.
  • false
    • php-cs-fixer is executed with the legacy PHP_CS_FIXER_IGNORE_ENV=1 environment variable.

The runner always adds --no-interaction to avoid interactive prompts.

Tool Usage

The tool is exposed to the AI agent as run_php_cs_fixer.

Dry run (check only)

{
  "toolName": "run_php_cs_fixer",
  "parameters": {
    "path": "src/Service/MyService.php",
    "fix": false
  }
}

Apply fixes

{
  "toolName": "run_php_cs_fixer",
  "parameters": {
    "path": "src/Service/MyService.php",
    "fix": true
  }
}

Custom timeout per call

{
  "toolName": "run_php_cs_fixer",
  "parameters": {
    "path": "src/Service/MyService.php",
    "fix": true,
    "timeout": 120
  }
}

The timeout parameter specifies a custom timeout in seconds for a single tool invocation. It must not exceed the configured max_timeout; otherwise, the tool will fail with an execution error.

The result contains:

  • command – the executed command string,
  • exitCode – process exit code,
  • stdout – sanitized standard output,
  • stderr – sanitized standard error output,
  • success – boolean indicating success,
  • cwd – working directory for the executed command.