PHP version dectection with composer.json breaks when composer.json is not in the root of the project

Author: blackwolf12333Created Feb 6, 2026Updated Aug 22, 2026
Labelskind/bugstatus/to verifystatus/stale

Problem description

When your project does not have composer.json in the same directory as the php-cs-fixer configuration a big 2 line warning is printed that the php version can't be determined from the composer.json file. This really clutters the output with a warning I can't do anything about because our project is configured in a specific way.

I'd prefer if the warning could be shorter, or add an option to provide the path to the composer.json file.

Minimal reproducer CLI command

app/vendor/bin/php-cs-fixer fix

Minimal reproducer code snippet

A project with the following files:

app/src/script.php app/composer.json buildroot/healthcheck.php .php-cs-fixer.php rector.php

.php-cs-fixer.php:

<?php

$finder = (new PhpCsFixer\Finder())
    ->in(["app", "buildroot"])
    ->exclude([
    ])
    ->notName('rector.php');

return (new PhpCsFixer\Config())
    ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
    ->registerCustomFixers([
    ])
    ->setRules([
        'blank_line_before_statement' => [
            'statements' => ['if', 'for', 'foreach', 'return', 'while', 'do', 'switch', 'try'],
        ],
        'no_unused_imports' => true,
        '@PER-CS2.0' => true,
        '@PHP82Migration' => true,
        '@PHP83Migration' => true,
    ])
    ->setFinder($finder);

Fixer version

PHP CS Fixer 3.93.1 Exceptional Exception by Fabien Potencier, Dariusz Ruminski and contributors.

PHP version

PHP runtime: 8.3.24

How do you run Fixer?

Composer package

Contribution Checks

  • I have verified if this problem was already reported
  • I am familiar with "Feature or bug?"

Source: PHP-CS-Fixer/PHP-CS-Fixer