phpstan-strict-rules
phpstan-strict-rules copied to clipboard
Closure: report missing function parameter typehint and missing return type
Hi, I would like to enable for Closures the two rules already present for normal functions, MissingFunctionParameterTypehintRule
and MissingFunctionReturnTypehintRule
.
I found that master branch has this commit https://github.com/phpstan/phpstan-strict-rules/commit/491540d3bfa11e218cdba868c4128891ba63b72f which already enabled PHPStan\Rules\Missing\MissingClosureNativeReturnTypehintRule
, so I guess only the parameter typehint is still missing.
May I propose a PR for a MissingClosureParameterTypehintRule
?
Hi, the main blocker is that PHPStan currently does not read docblocks for closures. So things like union types or what’s in an array cannot be expressed for closures. We’d need to do that first and then adding such a rule would be easy.
MissingClosureNativeReturnTypehintRule is a little bit different. It looks at what you’re returning from the function, and if it can be expressed with a native typehint, it asks you to do so.
On Thu, 22 Aug 2019 at 14:27, Filippo Tessarotto [email protected] wrote:
Hi, I would like to enable for Closures the two rules already present for normal functions, MissingFunctionParameterTypehintRule and MissingFunctionReturnTypehintRule.
I found that master branch has this commit 491540d https://github.com/phpstan/phpstan-strict-rules/commit/491540d3bfa11e218cdba868c4128891ba63b72f which already enabled PHPStan\Rules\Missing\MissingClosureNativeReturnTypehintRule, so I guess only the parameter typehint is still missing.
May I propose a PR for a MissingClosureParameterTypehintRule?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/phpstan/phpstan-strict-rules/issues/87?email_source=notifications&email_token=AAAZTOCUBETEUI6ULR7AO6TQF2A2DA5CNFSM4IOUMVPKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HGYWNSQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAZTOC4F5PLHXZUK4LLXVLQF2A2DANCNFSM4IOUMVPA .
--
Ondřej Mirtes
PHPStan currently does not read docblocks for closures
Ok then, I'll wait for a PR.
For those who don't want to wait, don't use docblocks for closures and don't handle mixed types, a simple rule like this can be added to the project:
https://github.com/Slamdunk/phpstan-extensions/blob/v3.6.0/lib/MissingClosureParameterTypehintRule.php