1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix erroneous complaint for str_replace

This commit is contained in:
Brown 2019-08-13 14:26:25 -04:00
parent 0468d11158
commit 55cfbdcd5f
2 changed files with 14 additions and 3 deletions

View File

@ -337,12 +337,12 @@ class Functions
$args
);
if (!$function_callable->params) {
if (!$function_callable->params || !$args) {
return false;
}
foreach ($function_callable->params as $param) {
if ($param->by_ref) {
foreach ($function_callable->params as $i => $param) {
if ($param->by_ref && isset($args[$i])) {
return false;
}
}

View File

@ -42,6 +42,17 @@ class PureAnnotationTest extends TestCase
return substr(strtolower($s), 0, 10);
}',
],
'pureWithStrReplace' => [
'<?php
/** @psalm-pure */
function highlight(string $needle, string $output) : string {
$needle = preg_quote($needle, \'#\');
$needles = str_replace([\'"\', \' \'], [\'\', \'|\'], $needle);
$output = preg_replace("#({$needles})#im", "<mark>$1</mark>", $output);
return $output;
}'
],
];
}