Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support uppercase-string #11227

Open
VincentLanglet opened this issue Jan 30, 2025 · 1 comment
Open

Support uppercase-string #11227

VincentLanglet opened this issue Jan 30, 2025 · 1 comment

Comments

@VincentLanglet
Copy link
Contributor

In the same way psalm supports lowercase-string PHPStan does.
But PHPStan also supports uppercase-string. (phpstan/phpstan-src#3613)
https://phpstan.org/r/1bb5f514-6781-48a8-a775-70c8fbe8bb3a

Psalm currently does not understand the type https://psalm.dev/r/f5835a8213

When using both PHPStan and Psalm it's kinda annoying since it forces to use double annotation.

It would be great to supports uppercase-string for psalm too, but I feel like it may be more complicated in PHPStan because

  • PHPStan use an array of accessory (non-empty, non-falsy, lowercase, numeric, uppercase, literal, ...) so can easily represente any intersection of those types.
  • Psalm use a class for every existing intersection. So psalm has TNonEmptyString, TNonFalsyString, TNumericString, TLowercaseString, TNonEmptyLowercaseString, but is already missing classes like TNonFalsyLowercaseString, TNonFalsyNumericString (to exclude 0), TNumericLowercaseString (if you need to exclude 10E2) and introducing TUppercaseString would require multiple new classes (knowning that even TLowercaseUppercaseString is technically possible for string without letter like numbers or special characters).

So at least would it be easily possible for Psalm to consider uppercase-string as an alias for string, in order to avoid using double annotation when using both PHPStan and psalm ?

Copy link

I found these snippets:

https://psalm.dev/r/f5835a8213
<?php

/**
 * @param uppercase-string $string
 *
 * @return uppercase-string
 */
function foo(string $string) {
    return $string;
}
Psalm output (using commit c7c5a69):

ERROR: InvalidDocblock - 4:11 - Unrecognized type uppercase-string in docblock for foo

ERROR: InvalidDocblock - 8:1 - Unrecognized type uppercase-string in docblock for foo

INFO: MissingReturnType - 8:10 - Method foo does not have a return type, expecting string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant