From a8486810e7df79cc8109a7247db5a8cc6c5c1c79 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 15:24:18 +0200 Subject: [PATCH 1/2] Add CI reproducer for configured PHP-CS-Fixer fixer fatal error Covers https://github.com/ecsphp/ecs-src/issues/44 - configuring a fixer calls PhpCsFixer\Console\Application::getMajorVersion(), which extends the replaced symfony/console Application and fatals. --- .github/workflows/configured_fixer.yaml | 53 +++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/configured_fixer.yaml diff --git a/.github/workflows/configured_fixer.yaml b/.github/workflows/configured_fixer.yaml new file mode 100644 index 0000000000..35883dffe7 --- /dev/null +++ b/.github/workflows/configured_fixer.yaml @@ -0,0 +1,53 @@ +name: Configured Fixer + +# verifies https://github.com/ecsphp/ecs-src/issues/44 +# configuring a PHP-CS-Fixer fixer runs ConfigurableFixerTrait::configure(), which calls +# PhpCsFixer\Console\Application::getMajorVersion(). That class extends the Symfony console +# Application, which ECS replaces and does not ship - so the run must not fatal there. + +on: + pull_request: + push: + branches: + - main + +jobs: + configured_fixer: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + coverage: none + + - run: composer install --no-progress --ansi + + - + name: "Create a config with a configured PHP-CS-Fixer fixer" + run: | + mkdir -p build/nested + printf ' build/nested/some_file.php + cat > build/configured-fixer-ecs.php <<'PHP' + withPaths([__DIR__ . '/nested']) + ->withPreparedSets(psr12: true) + ->withConfiguredRule( + \PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer::class, + ['use_nullable_type_declaration' => false] + ); + PHP + + - + name: "ecs check must run without a fatal error" + run: | + OUTPUT="$(bin/ecs check --config=build/configured-fixer-ecs.php --no-progress-bar --ansi 2>&1 || true)" + echo "$OUTPUT" + echo "$OUTPUT" | grep -q 'some_file.php' + ! echo "$OUTPUT" | grep -q 'Fatal error' + ! echo "$OUTPUT" | grep -q 'Console\\Application" not found' From c599c7a22c3da150e1c2c60e389ac66a588b9b07 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 17:46:48 +0200 Subject: [PATCH 2/2] Add Symfony console Application stub, so configured php-cs-fixer fixers do not fatal PhpCsFixer\Console\Application extends Symfony\Component\Console\Application, which ECS replaces and never installs. ConfigurableFixerTrait::configure() calls its static getMajorVersion(), so PHP has to resolve the parent class. Shipping a declaration-only stub in /stubs makes it resolvable, in both plain source and the prefixed release build. --- .github/workflows/buid_release.yaml | 6 +++--- composer.json | 5 ++++- stubs/symfony-console-application.php | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 stubs/symfony-console-application.php diff --git a/.github/workflows/buid_release.yaml b/.github/workflows/buid_release.yaml index 945a240dac..64502109af 100644 --- a/.github/workflows/buid_release.yaml +++ b/.github/workflows/buid_release.yaml @@ -50,7 +50,7 @@ jobs: - run: rm -rf tests ecs-build/packages/coding-standard/tests ecs-build/ecs.php ecs-build/phpstan.neon ecs-build/phpunit.xml ecs-build/.gitignore ecs-build/.editorconfig # 2. downgrade via Rector - - run: rector-local/vendor/bin/rector process ecs-build/bin ecs-build/config/config.php ecs-build/packages ecs-build/src ecs-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs + - run: rector-local/vendor/bin/rector process ecs-build/bin ecs-build/config/config.php ecs-build/packages ecs-build/src ecs-build/stubs ecs-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs # 3. prefix classes - run: | @@ -59,8 +59,8 @@ jobs: # download php-scoper wget https://github.com/humbug/php-scoper/releases/download/0.18.17/php-scoper.phar -N --no-verbose - # scope /bin, /config, /packages, /src, /vendor and composer.json - php -d memory_limit=-1 php-scoper.phar add-prefix bin config packages/coding-standard/src src vendor composer.json --output-dir ../ecs-prefixed-downgraded --config scoper.php --force --ansi --working-dir ecs-build + # scope /bin, /config, /packages, /src, /stubs, /vendor and composer.json + php -d memory_limit=-1 php-scoper.phar add-prefix bin config packages/coding-standard/src src stubs vendor composer.json --output-dir ../ecs-prefixed-downgraded --config scoper.php --force --ansi --working-dir ecs-build # dump composer autoload composer dump-autoload --working-dir ecs-prefixed-downgraded --ansi --classmap-authoritative --no-dev diff --git a/composer.json b/composer.json index 5121355024..1ce82ecbca 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,10 @@ "psr-4": { "Symplify\\EasyCodingStandard\\": "src", "Symplify\\CodingStandard\\": "packages/coding-standard/src" - } + }, + "classmap": [ + "stubs" + ] }, "autoload-dev": { "psr-4": { diff --git a/stubs/symfony-console-application.php b/stubs/symfony-console-application.php new file mode 100644 index 0000000000..ffd4b5700c --- /dev/null +++ b/stubs/symfony-console-application.php @@ -0,0 +1,22 @@ +