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

Static method should return static(X) but returns X. #4648

Closed
MetalArend opened this issue Mar 3, 2021 · 10 comments
Closed

Static method should return static(X) but returns X. #4648

MetalArend opened this issue Mar 3, 2021 · 10 comments
Labels
Milestone

Comments

@MetalArend
Copy link

Bug report

I saw issue #2885, and updated to the latest version 0.12.80. But the issue remained.

Code snippet that reproduces the problem

https://phpstan.org/r/c64505e0-5173-424a-a5da-1f8ca503997a

Expected output

The output is Method ClassImplementation::convert() should return static(ClassImplementation) but returns ClassImplementation.. Afaik the implementation should be completely acceptable. It looks a lot like issue #2885, maybe it has something to do with the method being?

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 3, 2021
@ondrejmirtes
Copy link
Member

Right now you can use new static() which is equivalent to new self() in a final class. https://phpstan.org/r/224dba41-323a-4d45-8885-a0b697018602

@MetalArend
Copy link
Author

@ondrejmirtes That was quick :D

@MetalArend
Copy link
Author

That would be an option, if I would not have simplified that bit for the report. I'm actually doing something like self::fromExternalValueObject, which is written somewhere in a dependency. 😢

@ondrejmirtes
Copy link
Member

Can you write a more specific example to your situation? Also, are you aware of the stub files aimed at overriding wrong 3rd party PHPDocs? https://phpstan.org/user-guide/stub-files

@MetalArend
Copy link
Author

I added the ExternalDependency and the OtherClass.

https://phpstan.org/r/adf566da-efb5-46da-93d2-d13d368934ac

I was not aware of the stub files, I'll have to check it out. Thanks for the tip! For now, I simply ignored the error, and phpstan will eventually tell me that that ignored error is not happening anymore 😄

@ondrejmirtes
Copy link
Member

This is how the code should look: https://phpstan.org/r/73ab08ff-bda4-4a66-b20c-ef7fadacacd9

You can do that with stub files.

@MetalArend
Copy link
Author

Nice!!! Thanks, again 🥇

@phpstan-bot
Copy link
Contributor

@MetalArend After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-18: Method ClassImplementation::convert() should return static(ClassImplementation) but returns ClassImplementation.
+No errors

@phpstan-bot
Copy link
Contributor

@MetalArend After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-20: Method ClassImplementation::convert() should return static(ClassImplementation) but returns ClassImplementation.
+No errors

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants