Repository navigation
Conversation
PHPStan 2.3.5 marks errors it can fix automatically and suggests to run it again with --fix. When the analysis reports such errors, the phpstan task now returns a fixable result that reruns the same command with --fix, like the other fixable tasks. The fixer is only offered when PHPStan reports fixable errors: without them, "phpstan analyse --fix" fails with "No fixable errors found".
Since symfony/yaml 7.4.22 and 8.1.10, ParseException::getSnippet() and ParseException::getParsedFile() are declared as nullable. Psalm fails on the highest dependencies, and a parse error without snippet ends in a TypeError when creating the YamlLintError. Fall back to an empty string.
This branch has not been deployed
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.
PHPStan 2.3.5 made many built-in errors auto-fixable (e.g.
method.missingOverride,cast.useless,phpunit.*). It marks them with 🔧 and ends its report with "Run PHPStan again with --fix".This PR plugs that into GrumPHP's fixer the same way as the other fixable tasks (ECS, Rector, Mago): when the analysis fails and PHPStan reports fixable errors, the
phpstantask returns aFixableTaskResultthat reruns the samephpstan analysecommand with--fix(same files, configuration, level and memory limit).Why only when PHPStan reports fixable errors?
phpstan analyse --fixexits with 1 and "No fixable errors found", so GrumPHP would ask to fix and then report a failing fixer.--fixlaunched PHPStan Pro instead of fixing.)The hint for fixable ignored errors (
--fix-ignored) is deliberately not taken into account, since ignored errors don't make the task fail. If PHPStan ever rewords the hint, the task falls back to the current non-fixable behaviour.Tested manually against the PHPStan phars
--fixexits with 0 even though the non-fixable error remains, the fixer reports ✔ and only#[\Override]was added.The docs mention that
--fixis experimental in PHPStan and also removes unmatchedignoreErrorsentries from the configuration/baseline and unmatched@phpstan-ignorecomments.New Task Checklist:
phpstan/phpstanis already suggested)doc/tasks/phpstan.md)test/Unit/Task/PhpStanTest.phpcovers fixable, non-fixable and fixable-ignored output and the fix command)run()method readable?run()method using the configuration correctly? (the fix command reuses the same arguments)