Uh oh!
There was an error while loading. Please reload this page.
Fix support for classes named after pseudotypes in phpdoc - #365
Conversation
stof
commented
Nov 1, 2020
@ondrejmirtes any guidance about where I should add a test covering this ? |
stof
commented
Nov 2, 2020
Note that once this is released, the doc at https://phpstan.org/writing-php-code/phpdocs-basics#classes-named-after-internal-php-types should be updated to stop talking about |
ondrejmirtes
commented
Nov 2, 2020
Hi, I'd be pretty careful with this. It might be a BC break for some people. I'd rather be it this was a TypeNodeResolverExtension enabled via bleedingEdge in Also, we could (and should) do it for more similar types like |
stof
commented
Nov 2, 2020
@ondrejmirtes AFAICT, If this approach about preferring an existing class over the pseudotype for valid class names works for you, applying it to |
ondrejmirtes
commented
Nov 2, 2020
I'd like some additional logic:
You can test this in NodeScopeResolver::testFileAsserts by adding a new data provider and see how the existing data providers work like. |
stof
commented
Nov 2, 2020
do you have any example for that ? |
ondrejmirtes
commented
Nov 2, 2020
TypeNodeResolverExtension: https://github.com/phpstan/phpstan-phpunit/blob/master/src/PhpDoc/PHPUnit/MockObjectTypeNodeResolverExtension.php
But feel free to implement and test the logic as it is. I have a feeling that the NodeScopeResolverTest will not see the stuff registered behind bleedingEdge tag right now. |
stof
commented
Nov 2, 2020
@ondrejmirtes what is the expected order for these 2 rules ? What should I do if a file without namespace contains a use statement ? |
ondrejmirtes
commented
Nov 2, 2020
Use the use statement 😊 |
stof
commented
Nov 2, 2020
@ondrejmirtes I pushed an update implementing the new logic. The tests are not yet done though. |
ondrejmirtes
commented
Nov 2, 2020
Please don't do that for the names that are affected by this warning: https://3v4l.org/f1UF7 |
stof
commented
Nov 2, 2020
ah, I was not aware of that warning on PHP 8. I tried defining a class but not typehinting it. |
ondrejmirtes
commented
Nov 4, 2020
@stof Hi, just asking - when will you have time to finish this PR? Thanks. |
stof
commented
Nov 4, 2020
@ondrejmirtes I'll try to do it this evening |
stof
commented
Nov 4, 2020
Looks like and it still treat that as a class typehint in all PHP versions. The only impacted thing is how you write the typehint when using such class name (you cannot use an unqualified lowercase name) |
stof
commented
Nov 24, 2020
@ondrejmirtes given that the warning only applies to lowercase names, should I really disqualify them entirely ? |
d45166a to
3526237Comparestof
commented
Mar 3, 2021
@ondrejmirtes I added tests covering this. But the tests for classes existing in the same namespace (without use statements) don't work because it looks like the |
ondrejmirtes
commented
Mar 3, 2021
@stof It should be fine, you need to run Also, please use the modern style tests in |
stof
commented
Mar 3, 2021
@ondrejmirtes I updated to the modern style, and I added a |
ondrejmirtes
left a comment
There was a problem hiding this comment.
I love this, I really really do. Looks like it will solve problems people have without actually breaking anything.
One more thing to fix and I'll click the Merge button :)
There was a problem hiding this comment.
Instead of this leaking of NameScope internals, I'd add NameScope::hasUseAlias().
The non-standard pseudotype
int|floatwill be used only if the resolved class does not exist.Closesphpstan/phpstan#4039