Skip to content
Permalink
Browse files

Fix #2468 - add support for zipping arrays

  • Loading branch information
muglug committed Dec 18, 2019
1 parent 734ad02 commit 456aa1c5692f1dec56e977ad1903f7ca7e2d4501
@@ -39,6 +39,31 @@ public static function getFunctionReturnType(
return Type::getMixed();
}

$function_call_arg = $call_args[0] ?? null;

$function_call_type = $function_call_arg
? $statements_source->node_data->getType($function_call_arg->value)
: null;

if ($function_call_type && $function_call_type->isNull()) {
\array_shift($call_args);

$array_arg_types = [];

foreach ($call_args as $call_arg) {
$call_arg_type = $statements_source->node_data->getType($call_arg->value);

if ($call_arg_type) {
$array_arg_types[] = clone $call_arg_type;
} else {
$array_arg_types[] = Type::getMixed();
break;
}
}

return new Type\Union([new Type\Atomic\ObjectLike($array_arg_types)]);
}

$array_arg = isset($call_args[1]->value) ? $call_args[1]->value : null;

$array_arg_atomic_type = null;
@@ -56,18 +81,14 @@ public static function getFunctionReturnType(
$generic_key_type = null;
$mapping_return_type = null;

if (isset($call_args[0])) {
$function_call_arg = $call_args[0];

if ($function_call_arg && $function_call_type) {
if (count($call_args) === 2) {
$generic_key_type = $array_arg_type->key ?? Type::getArrayKey();
} else {
$generic_key_type = Type::getInt();
}

if (($function_call_type = $statements_source->node_data->getType($function_call_arg->value))
&& ($closure_types = $function_call_type->getClosureTypes())
) {
if ($closure_types = $function_call_type->getClosureTypes()) {
$closure_atomic_type = \reset($closure_types);
$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();

@@ -2320,6 +2320,20 @@ function foo(array $strings): array {
return array_map("intval", $strings);
}'
],
'arrayMapZip' => [
'<?php
/**
* @return array{array{string,string|null}}
*/
function getCharPairs(string $line) : array {
$chars = str_split($line);
return array_map(
null,
$chars,
array_slice($chars, 1)
);
}'
],
];
}

0 comments on commit 456aa1c

Please sign in to comment.
You can’t perform that action at this time.