Repository navigation
Add @arguments-by-name, @optional-arguments-by-name and @stable-parameter-names support - #6741
Open
nicolas-grekas wants to merge 4 commits into
Open
nicolas-grekas wants to merge 4 commits into
nicolas-grekas wants to merge 4 commits into
Conversation
…parameter-names` support PHPStan now reports a positional argument when the PHPDoc of the called function, method or class requires it to be passed by name. `@stable-parameter-names` is parsed but reports nothing at call sites.
This was referenced Oct 14, 2026
[Contributing] Extend the BC promise to parameter names of tagged methods
symfony/symfony-docs#23350
Open
…gs win A tag on a method now wins over a class-level tag, including a class-level `@no-named-arguments`. Constructors no longer inherit the tags of the parent constructor. The new arguments of `FunctionCallParametersCheck::check()` are now optional and last, so extensions that call it keep working.
Constructors are not checked.
A private method is only called by its own class, so how it is called doesn't matter to other packages.
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.
This PR adds support for three PHPDoc tags. They tell callers how to pass arguments, and which part of a signature is covered by backward compatibility.
With
@optional-arguments-by-name, the arguments of optional parameters must be passed by name. Their names are stable, their order is not. With@arguments-by-name, every argument must be passed by name.@stable-parameter-namesallows both styles, because names and order are both stable.Like
@no-named-arguments, the tags can be put on a function, a method or a class. A class-level tag applies to the public and protected methods of the class, and to the methods that override or implement them. A method-level tag wins over a class-level one, including a class-level@no-named-arguments. Constructors don't inherit the tags of the parent constructor.When a method overrides or implements a tagged method, renaming a covered parameter is reported too. All parameters are covered by
@arguments-by-nameand@stable-parameter-names, and optional ones by@optional-arguments-by-name.@no-named-argumentswins when it's on the same docblock as one of the new tags. I didn't put this behind bleeding edge since nothing is reported until a library adds one of the tags. Calls through callables are not checked yet, because callable types don't know about the tags.stof asked for this in phpstan/phpstan#14386, after the discussion in symfony/symfony-docs#14566 back in 2020. Ondřej suggested hardcoding the Symfony cases in phpstan-symfony first. Like stof, I'd rather have the tags in the code. They follow each version of the library, and the need isn't specific to Symfony. Psalm gets the same tags in vimeo/psalm#12389, which builds on GromNaN's
@only-named-argumentsfrom vimeo/psalm#11791 (our@arguments-by-name).Closes phpstan/phpstan#14386
Symfony docs: symfony/symfony-docs#23350