Skip to content
Permalink
Browse files

Fix erroneous complaint for str_replace

  • Loading branch information...
muglug committed Aug 13, 2019
1 parent 0468d11 commit 55cfbdcd5f9e08773afa71d045b26b3d598bd265
Showing with 14 additions and 3 deletions.
  1. +3 −3 src/Psalm/Internal/Codebase/Functions.php
  2. +11 −0 tests/PureAnnotationTest.php
@@ -337,12 +337,12 @@ public function isCallMapFunctionPure(Codebase $codebase, string $function_id, a
$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;
}
}
@@ -42,6 +42,17 @@ function lower(string $s) : string {
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;
}'
],
];
}

0 comments on commit 55cfbdc

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