phpstan: PHPDoc block is ignored for closures/anonymous functions
Bug report
spl_autoload_register(
/**
* @param class-string $class_name The fully-qualified class name.
* @return void
*/
static function ($class_name) {
Parameter #1 $autoload_function of function spl_autoload_register expects callable(string): void, Closure(mixed): mixed given.
Code snippet that reproduces the problem
https://phpstan.org/r/56909d36-0d70-4c8d-990a-be01e822c572
Expected output
No error.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 11
- Comments: 16 (11 by maintainers)
Commits related to this issue
- Add a note and TODO about phpstan/phpstan#3770. — committed to loophp/collection by drupol 3 years ago
- Update Span and Partition operations. (#148) * show partition failure (cherry picked from commit 9eaf340cc37746f65d6626559e76be4336f50c14) * Another example (cherry picked from commit 5afe28... — committed to loophp/collection by drupol 3 years ago
This feature isn’t hard but there’s quite a few places we need to think of. I made a list of points that we need to keep track of during development:
NodeScopeResolver::getPhpDocs()is called: https://github.com/phpstan/phpstan-src/blob/6506d876ed0cfb625af3d749a19270706df7640b/src/Analyser/NodeScopeResolver.php#L3820callablesignature, the parameters are inferred based on that signature: https://github.com/phpstan/phpstan-src/blob/6506d876ed0cfb625af3d749a19270706df7640b/src/Analyser/NodeScopeResolver.php#L2931-L2946array_map, the first parameter type is inferred from the array passed toarray_map(for the purpose of analysing the closure body): https://github.com/phpstan/phpstan-src/blob/6506d876ed0cfb625af3d749a19270706df7640b/src/Reflection/ParametersAcceptorSelector.php#L74-L106array_filter, the first parameter type is inferred from the array passed toarray_filter(for the purpose of analysing the closure body): https://github.com/phpstan/phpstan-src/blob/6506d876ed0cfb625af3d749a19270706df7640b/src/Reflection/ParametersAcceptorSelector.php#L108-L150@returnis present in the PHPDoc, we probably don’t need to do this inference.array_mapcall this is used to figure out the return type of thearray_mapcall.The extra features mentioned in the list subitems should probably be turned off when PHPDoc is present.
Additionally, there should be new rules:
stringin@parambut for native typeintetc.FunctionTemplateTypeRule.This should be done over multiple small PRs which is the way I like to work.
I also offer to implement this for a fee paid against an invoice I’d issue. My estimate as what this would cost to have this developed by myself is 1500-2000 EUR. Feel free to reach out if you’re interested 😃