Fix support for classes named after pseudotypes in phpdoc#365
Fix support for classes named after pseudotypes in phpdoc#365ondrejmirtes merged 1 commit intophpstan:masterfrom
Conversation
|
@ondrejmirtes any guidance about where I should add a test covering this ? |
|
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 |
|
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 |
|
@ondrejmirtes AFAICT, If this approach about preferring an existing class over the pseudotype for valid class names works for you, applying it to |
|
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. |
do you have any example for that ? |
|
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. |
@ondrejmirtes what is the expected order for these 2 rules ? What should I do if a file without namespace contains a use statement ? |
|
Use the use statement 😊 |
497b34c to
d952fa1
Compare
|
@ondrejmirtes I pushed an update implementing the new logic. The tests are not yet done though. |
|
Please don't do that for the names that are affected by this warning: https://3v4l.org/f1UF7 |
|
ah, I was not aware of that warning on PHP 8. I tried defining a class but not typehinting it. |
|
@stof Hi, just asking - when will you have time to finish this PR? Thanks. |
|
@ondrejmirtes I'll try to do it this evening |
|
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) |
|
@ondrejmirtes given that the warning only applies to lowercase names, should I really disqualify them entirely ? |
d45166a to
3526237
Compare
|
@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 |
|
@stof It should be fine, you need to run Also, please use the modern style tests in |
|
@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 :)
src/PhpDoc/TypeNodeResolver.php
Outdated
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.Closes phpstan/phpstan#4039