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
Return of void method reported as used, when it is not #1656
Comments
|
Yes it is, but it is not relevant IMO. The rule is about "usage of void return" not about "found expressions that throw away results".
I disagree. First of all, readability is a subjective thing, so what's readable for you it is not necesarily for me. And for me, a thing like: if (!$thing->isInitialized()) {
$thing->initialize();
} is far less readable then:
But that's totally unrelevant IMO. I don't think PHPStan is about finding unreadable things, I think it is about finding (possible) bugs, and the code above has no sign of being buggy. I am not familiar with the internals of PHPStan and I'm not sure how hard it is to implement this, but IMO the error should be raised only if the return value of a void function is either assigned (to a variable, a constant, or a class property), passed to a function, or returned from a function. In any other case, there should be no error. |
Shortness does not automatically imply readability. You're using As for the rest, I never disagreed with you:
|
Just to contribute, I believe I have roughly the same issue, unless I'm missing something obvious. I'm getting the same error on this code... private function error(string $message): void
{
throw new ValidateException($message);
} My travis output may also be of use: |
@RobDWaller That looks unrelated. Please open a separate issue with reproduction on phpstan.org. |
@ondrejmirtes you're right, I spoke too soon. Apologies for taking up your time. Keep up the great work. 👍 |
IMO |
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. |
Summary of problem
The rule: "Result of method {xxx} (void) is used" should IMO check that the result of a void method is actually used, i.e. set to a variable or passed to a function/method...
However it does not seems to work like that.
Code snippet that reproduces the problem
https://phpstan.org/r/dea43fe8-b309-491b-bdde-b06bfcbaed88
Expected output
I would expect the rule to report an error only if the void return is actually used.
The text was updated successfully, but these errors were encountered: