Skip to content

Commit

Permalink
Add support for callable in array_reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Aug 24, 2022
1 parent 034a796 commit 6bc714c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev

$initial_type = $reduce_return_type;

if ($closure_types = $function_call_arg_type->getClosureTypes()) {
if ($closure_types = $function_call_arg_type->getClosureTypes() ?: $function_call_arg_type->getCallableTypes()) {
$closure_atomic_type = reset($closure_types);

$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();
Expand Down
16 changes: 16 additions & 0 deletions tests/ClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,22 @@ function maker(string $className) {
'$result' => 'array{stdClass}'
],
],
'CallableWithArrayReduce' => [
'<?php
/**
* @return callable(int, int): int
*/
function maker() {
return function(int $sum, int $e) {
return $sum + $e;
};
}
$maker = maker();
$result = array_reduce([1, 2, 3], $maker, 0);',
'assertions' => [
'$result' => 'int'
],
],
'FirstClassCallable:NamedFunction:is_int' => [
'<?php
$closure = is_int(...);
Expand Down

0 comments on commit 6bc714c

Please sign in to comment.