RequiredPhpVersionVisitor: report named arguments as requiring PHP 8.0#5890
Merged
staabm merged 1 commit intoJun 17, 2026
Merged
Conversation
- Detect named arguments via a single `Node\Arg` check with a non-null `name`, which covers every call context at once: function calls, method calls, nullsafe method calls, static calls, `new` expressions and attributes. - Add `testDetectedVersion` cases for named arguments across all those contexts plus a negative case for positional-only arguments. - Add `// lint >= 8.0` comments to the fixtures the new detection flagged so they are skipped on older PHP versions in CI. For the two `nsrt` fixtures (consumed by TypeInferenceTestCase, which requires the comment to immediately follow `<?php`), the comment is placed on its own first line and the `declare()` moved down; the line-sensitive expectations in CallCallablesRuleTest::testBug4510 are bumped by one line accordingly.
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.
Summary
RequiredPhpVersionVisitordetects the minimum PHP version a test fixture needs to be parsed, so CI can skip it on older PHP versions instead of hitting a hard parse error. It did not recognize named arguments, which require PHP 8.0. This PR teaches it to report named arguments, following up on the same work done for other version-gated syntax (phpstan/phpstan#14816, phpstan/phpstan#14824, phpstan/phpstan#14831, #5855).Changes
build/PHPStan/Build/RequiredPhpVersionVisitor.php: reportnamed argumentsas requiring PHP 8.0 when aNode\Arghas a non-nullname. A single check on theArgnode covers all call contexts — function calls, method calls, nullsafe method calls, static calls,newexpressions and attributes — instead of enumerating each call type.tests/PHPStan/Build/RequiredPhpVersionCommentTest.php: addtestDetectedVersioncases for named arguments in function calls, method calls, nullsafe method calls, static calls,new, and attributes, plus a negative case asserting positional-only arguments require nothing.// lint >= 8.0comments to the 25 fixtures that the new detection correctly flagged as using named arguments without advertising the version.nsrtfixtures (bug-4510.php,bug-5262.php), which are consumed byTypeInferenceTestCasethat requires the// lintcomment to immediately follow<?php, the comment is placed on its own first line anddeclare()moved to the next line.CallCallablesRuleTest::testBug4510asserts errors on specific lines ofbug-4510.php, so its expected line numbers are bumped by one.Root cause
The visitor enumerated which syntactic features require which PHP version but had no entry for named arguments. Rather than adding the check to each of the four call-expression branches it already handled (and still missing
newand attributes), the fix queries theNode\Argnode directly: a named argument is exactly anArgwhosenameis set, regardless of the enclosing construct, so one check sweeps the entire call-argument axis.Test
RequiredPhpVersionCommentTest::testDetectedVersiongains cases proving named arguments are reported as PHP 8.0 in function/method/nullsafe-method/static calls,new, and attributes, and that positional-only arguments report nothing. These fail without the visitor change.RequiredPhpVersionCommentTest::testFixtureHasRequiredLintComment(which runs over everydata/nsrtfixture) now passes after the flagged fixtures received their// lint >= 8.0comments.make testsandmake phpstanpass.Refs phpstan/phpstan#14835