Skip to content
Permalink
Browse files

Allow array_map alone when it uses a closure

  • Loading branch information...
muglug committed Sep 10, 2019
1 parent 9afdff5 commit deb36e8b273d4b25601f1991482a69d412e3169f
@@ -15,6 +15,7 @@
use function strpos;
use function strtolower;
use function substr;
use Closure;
/**
* @internal
@@ -365,7 +366,8 @@ public function isCallMapFunctionPure(
return false;
}
$must_use = true;
$must_use = $function_id !== 'array_map'
|| (isset($args[0]) && !$args[0]->value instanceof \PhpParser\Node\Expr\Closure);
foreach ($function_callable->params as $i => $param) {
if ($param->type && $param->type->hasCallableType() && isset($args[$i])) {
@@ -38,7 +38,6 @@
unset($args[$psalm_proxy]);
}
/** @psalm-suppress UnusedFunctionCall */
array_map(
/**
* @param string $arg
@@ -27,7 +27,6 @@
// get options from command line
$options = getopt(implode('', $valid_short_options), $valid_long_options);
/** @psalm-suppress UnusedFunctionCall */
array_map(
/**
* @param string $arg
@@ -89,7 +89,6 @@
exit;
}
/** @psalm-suppress UnusedFunctionCall */
array_map(
/**
* @param string $arg
@@ -29,7 +29,6 @@
// get options from command line
$options = getopt(implode('', $valid_short_options), $valid_long_options);
/** @psalm-suppress UnusedFunctionCall */
array_map(
/**
* @param string $arg
@@ -614,6 +614,12 @@ function foo(array $arr) : array {
return $arr;
}'
],
'allowArrayMapWithClosure' => [
'<?php
$a = [1, 2, 3];
array_map(function($i) { echo $i;}, $a);'
],
];
}

0 comments on commit deb36e8

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