Skip to content

Commit

Permalink
Add better support for preg_replace_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 5, 2019
1 parent 422d994 commit aa3df3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/CallMap.php
Expand Up @@ -9958,7 +9958,7 @@
'preg_match_all' => ['int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
'preg_quote' => ['string', 'str'=>'string', 'delim_char='=>'string'],
'preg_replace' => ['string|string[]|null', 'regex'=>'string|array', 'replace'=>'string|array', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_replace_callback' => ['string|string[]|null', 'regex'=>'string|array', 'callback'=>'callable(array):string', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_replace_callback' => ['string|string[]|null', 'regex'=>'string|array', 'callback'=>'callable(array<int, string>):string', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_replace_callback_array' => ['string|string[]|null', 'pattern'=>'array<string,callable(array):string>', 'subject'=>'string|array', 'limit='=>'int', '&w_count='=>'int'],
'preg_split' => ['array<int,string>|false', 'pattern'=>'string', 'subject'=>'string', 'limit'=>'?int', 'flags='=>'null'],
'preg_split\'1' => ['array<int,string>|array[]|false', 'pattern'=>'string', 'subject'=>'string', 'limit='=>'?int', 'flags='=>'int'],
Expand Down
13 changes: 13 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -1768,6 +1768,19 @@ function in_array($a, $b) {
}
}'
],
'pregReplaceCallback' => [
'<?php
function foo(string $s) : string {
return preg_replace_callback(
\'/<files (psalm-version="[^"]+") (?:php-version="(.+)">\n)/\',
/** @param array<int, string> $matches */
function (array $matches) : string {
return $matches[1];
},
$s
);
}',
],
];
}

Expand Down

0 comments on commit aa3df3f

Please sign in to comment.