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

@throws void is ignored in a stub file #7552

Closed
VincentLanglet opened this issue Jun 29, 2022 · 4 comments · Fixed by phpstan/phpstan-src#1487
Closed

@throws void is ignored in a stub file #7552

VincentLanglet opened this issue Jun 29, 2022 · 4 comments · Fixed by phpstan/phpstan-src#1487
Labels
Milestone

Comments

@VincentLanglet
Copy link
Contributor

Bug report

I have the following stub file

<?php

/**
 * We can consider that this method will never throw an exception
 *
 * @throws void
 */
function random_int(int $min, int $max): int {}

And I added my php.stub file to the stubFiles section of my phpstan.neon.
I also use missingCheckedExceptionInThrows.

Expected output

When I use random_int I would expect no error from phpstan but I get

... throws checked exception Exception but it's missing from the PHPDoc @throws tag

Am I doing something wrong or would it be possible that the throws void is not correctly handled in a stub file for native functions.

Did PHPStan help you today? Did it make you happy in any way?

Sure, trying to integrate the exceptions checks.

@mergeable
Copy link

mergeable bot commented Jun 29, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

I see that https://github.com/phpstan/phpstan-src/blob/1.8.x/src/Reflection/SignatureMap/NativeFunctionReflectionProvider.php doesn't use the stub file to override the @throws type and it's easy to fix. Consider sending a PR, thanks.

This is an example how to test stubs-related problems: https://github.com/phpstan/phpstan-src/blob/1.8.x/tests/PHPStan/Analyser/ConditionalReturnTypeFromMethodStubTest.php

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 30, 2022
@VincentLanglet
Copy link
Contributor Author

Thanks I'll take a look.

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

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 Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants