Skip to content

[StaticTypeMapper] Map phpstan-special scalar types (literal-string, numeric-string, ...)#8176

Merged
TomasVotruba merged 3 commits into
mainfrom
map-literal-string-scalar-type
Jul 12, 2026
Merged

[StaticTypeMapper] Map phpstan-special scalar types (literal-string, numeric-string, ...)#8176
TomasVotruba merged 3 commits into
mainfrom
map-literal-string-scalar-type

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jul 12, 2026

Copy link
Copy Markdown
Member

Several PHPStan-special types were missing from ScalarStringToTypeMapper, so they fell through to a bogus ObjectType('...'). RemoveReturnTagIncompatibleWithNativeTypeRector then 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-string mappings) makes them genuine subtypes, so the rule now keeps them.

Newly mapped types

PHPDoc type Mapped to
literal-string AccessoryLiteralStringType
numeric-string AccessoryNumericStringType
non-falsy-string, truthy-string AccessoryNonFalsyStringType
lowercase-string AccessoryLowercaseStringType
uppercase-string AccessoryUppercaseStringType
non-negative-int int<0, max>
non-positive-int int<min, 0>
array-key int|string

Before (rule wrongly removed the precise type)

-    /**
-     * @return literal-string
-     */
     public function getTableAlias(): string
     {
         return 'n';
     }

After

    /**
     * @return literal-string
     */
    public function getTableAlias(): string
    {
        return 'n';
    }

Docblock kept — literal-string (and the others above) are legitimate narrowings of their native type.

@TomasVotruba TomasVotruba changed the title [StaticTypeMapper] Map literal-string docblock type to AccessoryLiteralStringType [StaticTypeMapper] Map phpstan-special scalar types (literal-string, numeric-string, ...) Jul 12, 2026
@TomasVotruba TomasVotruba merged commit ed944a1 into main Jul 12, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the map-literal-string-scalar-type branch July 12, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant