-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Make templating Psalm-specific #8769
Conversation
a43d469
to
7da82bc
Compare
Not sure it's the right decision since it works fine for psalm. https://psalm.dev/r/738daf594d The only other way to solve this is to drop the |
Maybe yeah. This means the solution would be to use a non-templated version for phpstan with |
9b7d61d
to
b5b1a70
Compare
I pushed a commit that does that, but that means we now have a different behavior for Psalm and for Phpstan, and it's going to be hard to satisfy both of them now. To illustrate this, I have added a test within the static analysis directory you introduced. |
b5b1a70
to
2674be4
Compare
@@ -321,11 +321,13 @@ public function hasFilters(); | |||
* {@inheritDoc} | |||
* | |||
* @psalm-param string|class-string<T> $className | |||
* @phpstan-param string|class-string<T> $className |
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.
* @phpstan-param string|class-string<T> $className | |
* @phpstan-param string $className |
Yes, it reflects more the reality of the different behavior of those libraries, but I clearly don't like it. If the feature-request is accepted by phpstan, maybe this code should be untouched. |
Phpstan requires that the template can be resolved in all cases, while Psalm seems to tolerate this ambiguous situation. See phpstan/phpstan#5175 (comment)
2674be4
to
8bb564d
Compare
Related: #6935 |
Deprecation should be introduced to the 2.x branch then ? |
Yes, we just created #8818 in case you want to contribute it. |
That's what I had in mind. If someone is using phpunit at a strict level, he'll have to add And one of the benefit is that this will fix the following issue phpstan/phpstan#5175 for all the 2.x user, without having to wait for the 3.0 for this. |
I think you might be right, we'll have to see how it looks in practice, IMO it might result in a lot of ignore rules to add for us, as some checks are going to appear redundant, like checking if the string contains a colon. |
I don't know… #8818 is about deprecating namespace aliases, but it does not remove them, so the issue will remain until 3.0 😬 |
I see three "solutions" then.
Since the deprecation is planned #8818 / #8820, I would say the option 3 seems the more natural and phpdoc can be pre-emptively fixed in 2.10 version. |
Thanks for laying out the 3 options again @VincentLanglet ! As you know, I'm not too fond of the 3rd option, since it will express that namespace aliases are no longer supported (and break some pipelines), when they will in fact still be supported. Not everybody treat deprecations as a failure in their CI. @orklah hi! Do you have a recommendation on this one? |
I agree that since namespace aliases are still supported, we shouldn't remove I also understand the behavior in PHPStan and I wouldn't see that as a bug in the tool. However, Doctrine is widely used and we're fortunate to have plugins custom made for it to handle the quirks that can't be handled natively with annotations. So my advice would be to use @psalm annotations to describe the ideal behavior, use @phpstan annotations that doesn't use templates, ignore the issues that may arise in phpstan and ping the maintainers of the phpstan doctrine plugin that a special handling is needed here. When namespace aliases will be removed, this will be easy to go back to a single annotation for both tools and the case will be removed in the plugin |
Sounds good to me! Does that sound OK to you @VincentLanglet ? |
Sure |
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.
There was so much thought put into this, that I'm not sure if I missed something important. 😅
But it will become easier once the aliases are gone.
If
$className
is a class-string, then we return an instance of thatclass. However, if it's an alias, things get complicated, and it's hard
to tell. There does not seem to be a way to express that for now.
We should probably consider dropping namespace aliases entirely and add
support for
::class
inside DQL if it's not the case already.Refs #8767 , phpstan/phpstan#5175 , cc @VincentLanglet