fix: support both PHPStan 1.x and 2.x signatures in gatherAnalyserErrors()#60
Open
herpaderpaldent wants to merge 1 commit into
Open
fix: support both PHPStan 1.x and 2.x signatures in gatherAnalyserErrors()#60herpaderpaldent wants to merge 1 commit into
herpaderpaldent wants to merge 1 commit into
Conversation
…ors() PHPStan 1.x: RuleErrorTransformer::transform() expects (string $nodeType, int $nodeLine) PHPStan 2.x: RuleErrorTransformer::transform() expects (array $fileNodes, Node $node) The previous code passed ([], $node) which works on PHPStan 2.x but throws a fatal TypeError on PHPStan 1.x because $nodeType must be string, not array. Add a private callTransform() helper that uses reflection (cached via static variable) to detect the installed PHPStan version's signature and dispatch to the correct call, fixing --type-coverage for PHPStan 1.x users without breaking PHPStan 2.x. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
gatherAnalyserErrors()inTestCaseForTypeCoveragecallsRuleErrorTransformer::transform()with arguments that only match the PHPStan 2.x signature, causing a fatalTypeErrorfor PHPStan 1.x users:The two signatures differ between major versions:
string $nodeTypeint $nodeLinearray $fileNodesNode $nodeThe previous code passed
([], $node)which satisfies PHPStan 2.x but throws a fatalTypeErroron PHPStan 1.x because$nodeTypemust bestring, notarray.Fix
Add a private
callTransform()helper that uses reflection (result cached via astaticvariable, so the check is done only once per process) to detect the installed PHPStan version's signature and dispatch to the correct call.transform($ruleError, $scope, $nodeType, $node->getLine())transform($ruleError, $scope, [], $node)This fixes
--type-coveragefor PHPStan 1.x users without breaking PHPStan 2.x.