We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi there 馃憢
My PHPstan version is : 1.10.35
My phpstan config is :
includes: - phpstan-baseline.neon - vendor/phpstan/phpstan/conf/bleedingEdge.neon parameters: level: 9 paths: - src exceptions: check: missingCheckedExceptionInThrows: true tooWideThrowType: true
I'm facing the following problem, I have a closure explicitly throwing an exception.
This closure is passed to a wider function (call), which expects a closure as a param and the closure could throw anything.
call
However, when I call this wider function (from main), I wish I can document that main could throw the closure exceptions but I cannot.
main
<?php declare(strict_types=1); class Foo { /** * @throws \ArgumentCountError */ public function main(int $value): void { $this->call(fn () => $this->callback($value)); } /** * @param \Closure(): void $closure */ protected function call(\Closure $closure): void { $closure(); } /** * @throws \ArgumentCountError */ protected function callback(int $value): void { if ($value > 5) { throw new \ArgumentCountError(); } } }
And PHPStan tells me :
Method Foo::main() has ArgumentCountError in PHPDoc @throws tag but it's not thrown.
I guess it's a problem with tooWideThrowType rule and I am pretty sure it should not happen.
tooWideThrowType
I feel like I am missing an instruction to either
$closure
Note : I have a (very not elegant) workaround using :
/** * @throws \ArgumentCountError */ public function main(int $value): void { /** * @throws \ArgumentCountError */ $this->call(fn () => $this->callback($value)); }
https://phpstan.org/r/57ddea74-f72f-4063-9f79-d5caee6849f2
鈿狅笍 snipper is fine since I cannot enable tooWideThrowType rule
Yes ! Big yes ! Thank you for this awesome product !
The text was updated successfully, but these errors were encountered:
See #5001 and phpstan/phpstan-src#2066.
The problem is that we don' know call will call the closure immediately. Your workaround with inline @throws is good enough.
@throws
Sorry, something went wrong.
See #5001 (comment), that might help you
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.
No branches or pull requests
Bug report
Hi there 馃憢
My PHPstan version is : 1.10.35
My phpstan config is :
I'm facing the following problem, I have a closure explicitly throwing an exception.
This closure is passed to a wider function (
call
), which expects a closure as a param and the closure could throw anything.However, when I call this wider function (from
main
), I wish I can document that main could throw the closure exceptions but I cannot.And PHPStan tells me :
I guess it's a problem with
tooWideThrowType
rule and I am pretty sure it should not happen.I feel like I am missing an instruction to either
call
is throwing whatever$closure
is throwingcall
parameter$closure
is throwing somethingNote : I have a (very not elegant) workaround using :
Code snippet that reproduces the problem
https://phpstan.org/r/57ddea74-f72f-4063-9f79-d5caee6849f2
Expected output
tooWideThrowType
ruleI guess it's a problem with
tooWideThrowType
rule and I am pretty sure it should not happen.Did PHPStan help you today? Did it make you happy in any way?
Yes ! Big yes ! Thank you for this awesome product !
The text was updated successfully, but these errors were encountered: