mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Support analysing preg_match_all args in reverse to infer matches type
This commit is contained in:
parent
681eff6dd4
commit
3605eeee04
@ -599,6 +599,10 @@ class ArgumentsAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
if ($method_id === 'preg_match_all' && count($args) > 3) {
|
||||
$args = array_reverse($args, true);
|
||||
}
|
||||
|
||||
foreach ($args as $argument_offset => $arg) {
|
||||
$function_param = $function_param_count > $argument_offset
|
||||
? $function_params[$argument_offset]
|
||||
|
@ -1325,16 +1325,22 @@ class FunctionCallTest extends TestCase
|
||||
'pregMatchAll' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-pure
|
||||
*
|
||||
* @return array<list<string>>
|
||||
*/
|
||||
function extractUsernames(string $input): array {
|
||||
preg_match_all(\'/@[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w)/\', $input, $matches);
|
||||
preg_match_all(\'/([a-zA-Z])*/\', $input, $matches);
|
||||
|
||||
return $matches;
|
||||
}'
|
||||
],
|
||||
'pregMatchAllOffsetCapture' => [
|
||||
'<?php
|
||||
function foo(string $input): array {
|
||||
preg_match_all(\'/([a-zA-Z])*/\', $input, $matches, PREG_OFFSET_CAPTURE);
|
||||
|
||||
return $matches[0];
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user