Repository navigation
[TypeDeclaration] Skip already documented generic type in AddParamTypeSplFixedArrayRector - #8730
Merged
TomasVotruba merged 1 commit intoOct 20, 2026
Conversation
…eSplFixedArrayRector The rule compares the existing @PARAM type with the GenericObjectType it wants to add. Tokens is not a generic class, so an existing "Tokens<Token>" tag resolves to "iterable<Token>&Tokens", which never equals the generic object type, and the tag is rewritten with fully qualified names. With php-cs-fixer's fully_qualified_strict_types shortening it back, the two tools never settle. Skip a param whose docblock already has a single-argument generic tag that resolves to the same fixed array class and item class, whatever the spelling of the names. Fixes rectorphp/rector#9933
Member
|
LGTM, lets give it a go 👌 |
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 rectorphp/rector#9933
AddParamTypeSplFixedArrayRectorrewrites an existing@param Tokens<Token> $tokenstag to@param \PhpCsFixer\Tokenizer\Tokens<\PhpCsFixer\Tokenizer\Token> $tokensas soon as one of the names is short, whether imported or in the same namespace. php-cs-fixer'sfully_qualified_strict_typesshortens it again, so the two tools flip the line on every run.The rule hands its
GenericObjectTypetoPhpDocTypeChanger::changeParamType(), which maps the existing tag to a PHPStan type and compares the two.Tokensis not a generic class, so PHPStan resolvesTokens<Token>toiterable<Token>&Tokens. That is never equal toTokens<Token>as aGenericObjectType, so the tag is replaced. The fully qualified spelling goes through the same path; it just prints the same text again, which is why only the short form shows up as a change.The rule now skips a param whose docblock already has a single-argument generic tag that resolves to the same fixed array class and the same item class. A plain
@param Tokens $tokensis still upgraded.Fixtures:
skip_short_named_generic_doc: importedTokens<Token>is left alone (fails onmain)skip_same_namespace_generic_doc: same-namespaceTokens<Token>is left alone (fails onmain)plain_doc:@param Tokens $tokensstill gets the generic typeThe existing fixture only had the php-cs-fixer classes missing, where the comparison happens to pass, so
stubs/PhpCsFixer/Tokenizer/Token.phpandTokens.phpare added, guarded byclass_exists()like the other stubs.