Skip to content
Permalink
Browse files

Add better support for preg_replace_callback

  • Loading branch information...
muglug committed Jul 5, 2019
1 parent 422d994 commit aa3df3f7a511ae4e12dedaa8f21552c47814fc5b
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/Psalm/Internal/CallMap.php
  2. +13 −0 tests/FunctionCallTest.php
'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'],
@@ -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
);
}',
],
];
}

0 comments on commit aa3df3f

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