Fix fatal error when configuring a PHP-CS-Fixer fixer - #62
Open
TomasVotruba wants to merge 2 commits into
Open
Conversation
Covers #44 - configuring a fixer calls PhpCsFixer\Console\Application::getMajorVersion(), which extends the replaced symfony/console Application and fatals.
…rs 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #44 and covers it in CI.
Cause
The bug does not need the scoped/prefixed release build - it reproduces on plain source, because
composer.jsonhas"replace": {"symfony/console": "*"}, soSymfony\Component\Console\Applicationis never installed.Configuring a fixer whose option is deprecated hits
ConfigurableFixerTrait::configure(), which callsPhpCsFixer\Console\Application::getMajorVersion(). That class extends the missing Symfony consoleApplication, and PHP must resolve the parent class before the static call:In the released package the very same class is reported under its prefixed name,
ECSPrefix202607\Symfony\Component\Console\Application.Fix
Ship a declaration-only stub in
/stubs, autoloaded via classmap. ECS never runs the php-cs-fixer console, so only the class declaration is needed.php-scoper prefixes the stub along with everything else, so the release build gets
ECSPrefix<YYYYMM>\Symfony\Component\Console\Application- exactly the name php-cs-fixer'sApplicationextends there (verified by running php-scoper over/stubswith this repo config).stubsis added to the downgrade and scoping steps of the build workflow.CI
New
Configured Fixerworkflow runsbin/ecs checkwith a configured fixer and asserts the run produces output instead of fatalling. It was red on the first commit of this PR and is green after the fix.before:
after:
Note on the failing Code Analysis job
PHPStan and Rector fail on this branch, but not because of it -
composer.lockis gitignored, so CI always resolves the latest dev tools. Onmain, with today's versions, the same two failures appear:Multiple services of type Rector\TypePerfect\Reflection\MethodNodeAnalyser found(DI conflict insiderector/type-perfect)readonly classchanges proposed by the newer Rector, all untouched by this PR