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

Stub out str_replace types

This commit is contained in:
Brown 2020-04-04 11:05:13 -04:00
parent b73b75f1a1
commit 94fefde376
2 changed files with 42 additions and 10 deletions

View File

@ -13,9 +13,6 @@ class StrReplaceReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnT
public static function getFunctionIds() : array
{
return [
'str_replace',
'str_ireplace',
'substr_replace',
'preg_replace',
'preg_replace_callback',
];
@ -42,14 +39,12 @@ class StrReplaceReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnT
$return_type = Type::getString();
if (in_array($function_id, ['preg_replace', 'preg_replace_callback'], true)) {
$return_type->addType(new Type\Atomic\TNull());
$return_type->addType(new Type\Atomic\TNull());
$codebase = $statements_source->getCodebase();
$codebase = $statements_source->getCodebase();
if ($codebase->config->ignore_internal_nullable_issues) {
$return_type->ignore_nullable_issues = true;
}
if ($codebase->config->ignore_internal_nullable_issues) {
$return_type->ignore_nullable_issues = true;
}
return $return_type;

View File

@ -326,4 +326,41 @@ function fclose(&$handle) : bool
*/
function sodium_memzero(string &$reference): void
{
}
}
/**
* @param string|string[] $search
* @param string|string[] $replace
* @param string|string[] $subject
*
* @psalm-return (
* $subject is string
* ? string
* : string[]
* )
*/
function str_replace($search, $replace, $subject, int &$replace_count = 0) {}
/**
* @param string|string[] $search
* @param string|string[] $replace
* @param string|string[] $subject
*
* @psalm-return (
* $subject is string
* ? string
* : string[]
* )
*/
function str_ireplace($search, $replace, $subject, int &$replace_count = 0) {}
/**
* @param string|string[] $subject
*
* @psalm-return (
* $subject is string
* ? string
* : string[]
* )
*/
function substr_replace ($subject, string $replacement, int $start, ?int $length = null) {}