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

Inline ignore not working on wrong return type implementation #3834

Closed
Dartui opened this issue Sep 6, 2020 · 4 comments
Closed

Inline ignore not working on wrong return type implementation #3834

Dartui opened this issue Sep 6, 2020 · 4 comments
Labels
Milestone

Comments

@Dartui
Copy link

Dartui commented Sep 6, 2020

Bug report

Hi. I don't know if it's intentional and I know that this situation never should happen in first place, however...

Interface in framework has defined invalid return type. I wanted to override it in my implementation and ignore errors from PHPStan with inline comment, but for me it is not working. I don't want to ignore this error globally, because most of the time this error is fine and should be fixed.

Code snippet that reproduces the problem

https://phpstan.org/r/b99b9305-2db9-4ec5-a2cc-9c8c2ddaa9f0

Expected output

Ignored error.

@ondrejmirtes
Copy link
Member

Hi, technically this should be ignorable so it's a valid bug, but there's a much better approach to your problem. What's bad about your approach is that when you typehint TestInterface somewhere, PHPStan will still think that TestInterface::set() returns an array. The correct way to approach this is with stub files: just create a stub file that looks like this and register it in your phpstan.neon:

interface TestInterface
{
    /**
     * Test method.
     *
     * @param  string  $test
     * @return string
     */
    public function set($test);
}

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Sep 6, 2020
@phpstan-bot
Copy link
Contributor

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

@@ @@
-22: Return type (string) of method Test::set() should be compatible with return type (array) of method TestInterface::set()
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9474696

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

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 Dec 8, 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