[StaticTypeMapper] Map phpstan-special scalar types (literal-string, numeric-string, ...)#8176
Merged
Merged
Conversation
…-string, non-negative/non-positive-int, array-key
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.
Several PHPStan-special types were missing from
ScalarStringToTypeMapper, so they fell through to a bogusObjectType('...').RemoveReturnTagIncompatibleWithNativeTypeRectorthen saw the native type as not a supertype of that bogus object and wrongly deleted the more precise docblock.Mapping each to its real PHPStan type (same pattern as the existing
non-empty-string/class-stringmappings) makes them genuine subtypes, so the rule now keeps them.Newly mapped types
literal-stringAccessoryLiteralStringTypenumeric-stringAccessoryNumericStringTypenon-falsy-string,truthy-stringAccessoryNonFalsyStringTypelowercase-stringAccessoryLowercaseStringTypeuppercase-stringAccessoryUppercaseStringTypenon-negative-intint<0, max>non-positive-intint<min, 0>array-keyint|stringBefore (rule wrongly removed the precise type)
After
Docblock kept —
literal-string(and the others above) are legitimate narrowings of their native type.