-   Notifications  You must be signed in to change notification settings 
- Fork 544
Introduce uppercase-string #3613
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very complete and very nice, thank you! Just one thing I noticed.
| One more thing - Windows tests are failing https://github.com/phpstan/phpstan-src/actions/runs/11749776276/job/32736693637?pr=3613 | 
| 
 Yes; it's related to this change where two reasons are given instead of one, and the PHP_EOL between them causes the Windows failures. After thinking about it some more, I believe it should remain as one reason (not two) and am trying to track down where the second reason is coming from. Any help there would be appreciated! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a few more things.
| After you rebase on top of 1.12.x with this commit ccfb4ab, the rule error tip should appear only once. | 
4c4f9b1 to 0767f80   Compare   | 
 That did the trick; thanks! | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR should be copied too. #3510
IntegerRangeType::toString and IntegerType::toString are both lowercase-string and uppercase-string.
And a whole reflection on lowercase-string&uppercase-string seems needed.
Cause if this intersection is lost the current code
/** @param lowercase-string $string */ public function acceptsOnlyLowercase($string) {} /** @var int $int */ $int = ...; acceptsOnlyLowercase((string) $int); // Will report an error and doesn't actually cf
 https://phpstan.org/r/e722e920-af05-4c7b-8290-1205df68c4f8
| In this case we need to verify that  Should be done in TypeCombinatorTest. | 
Addresses phpstan#3613 (comment) and phpstan#3613 (comment) The relevate lowercase-string tests do not seem to be affected ... ?
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current ToDo-list seems to be:
-  This comment need to be addressed 
 https://github.com/phpstan/phpstan-src/pull/3613/files#r1835752042
-  Same for https://github.com/phpstan/phpstan-src/pull/3613/files#r1835752521 
-  appendAccessoryCasedStringTypes need to be changed. 
-  lowercase-string|uppercase-stringshould be simplified asstring
-  We need to understand why parse_url/trimdoesn't produce the expected behavior.
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment), phpstan#3613 (comment), phpstan#3613 (comment) This intentionally causes tests to fail so @VincentLanglet et al. can debug.
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment) Instead of a 4-part if/elseif/else, this builds both lowercase and/or uppercase; then if neither was true, builds what would have been the final else case.
Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment), phpstan#3613 (comment), phpstan#3613 (comment) This intentionally causes tests to fail so @VincentLanglet et al. can debug.
Addresses phpstan#3613 (comment)
Addresses phpstan#3613 (comment) Instead of a 4-part if/elseif/else, this builds both lowercase and/or uppercase; then if neither was true, builds what would have been the final else case.
Copied from phpstan@22f0cab and phpstan@38151b7
554f614 to ebd50a3   Compare   There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need lowercase-string|uppercase-string to be simplified to string
| @VincentLanglet "This PR should be copied too. https://github.com/phpstan/phpstan-src/pull/3510" That one is merged into 1.12.x, and I have rebased since that PR, so I think it has been included now. Let me know if I am mistaken. | 
| @VincentLanglet "We also need  | 
| 
 You need to update 
 
  | 
| 
 Might need to be validated with @ondrejmirtes, but I think it's in  But it seems not easy to do cause Depends on how hard it is to handle, and how important it is to solve ; it might be postponed in another PR. Except my previous comment, I don't think I see anything to add on this PR ; good job | 
| I reviewed the whole PR again and I like it a lot! Thank you very much. If you wanted more challenges in the type system now that you proficient in it, there's no shortage of them I can throw at you :) | 
| great job! | 
| 
 I had a comment left about IntegerType::toString which is both lowercase and uppercase. I made the PR #3651 | 
| Thanks all, glad it turned out well! | 
| Do you think it would be doable to introduce something like html-string and sql-string? Wouldn't be too different from uppercase/lowercase-string. Idea being: mysqli_real_escape_string(string): sql-string, and htmlspecialchars(string): html-string, then concat would preserve the semantics (does it?) and stuff like that... The idea being that then mysqli_query(sql-string) and all output(html-string).. just gathering some preliminary input, i'd open a separate issue to discuss that. | 
| @thg2k I plan to do "nominal string type". Which means you'll be able to do  | 
| The implementation would look very similar to this PR. | 
This PR introduces
uppercase-stringin all places wherelowercase-stringis recognized, except for SprintfFunctionDynamicReturnTypeExtension.The omission is because
sprintf()format strings cannot be typed reliably asuppercase-stringbecause most of the formatting specifiers are lowercase. For example, the format string'FOO %s BAR'is treated as a plainstringrather thanuppercase-string, because%sis lowercase (even though it might represent an uppercase string).It appears that
lowercase-stringexhibits similar behavior. For example, consider the format stringfoo %F. It formats as the lowercase string 'foo' and a non-locale-aware float; the returned string will be the same afterstrtolower(), so it should be valid as alowercase-string.However, in
nsrt/lowercase-string-sprintf.php, if you addassertType('lowercase-string', sprintf('foo %F', $lowercase));, it will fail with:That's because
%Fis uppercase, even though it represents a float.If you consider these to be problems, they might be resolved by adding a new type,
printf-string, that can ignore the formatting specifiers when determiningisLowercase()andisUppercase(), but I imagine that would have rather broad implcations.Let me know how you'd like to proceed.