1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add better return type for preg_split

This commit is contained in:
Matt Brown 2020-10-12 13:04:28 -04:00
parent 5743471a19
commit f83b50460a
2 changed files with 26 additions and 0 deletions

View File

@ -602,6 +602,17 @@ function implode($glue, array $pieces = []) : string {}
*/
function explode(string $delimiter, string $string, int $limit = -1) : array {}
/**
* @psalm-pure
*
* @psalm-flow ($subject) -(array-assignment)-> return
*
* @return ($flags is 1|3|5|7 ? list<string>|false : non-empty-list<string>|false)
*
* @psalm-ignore-falsable-return
*/
function preg_split(string $pattern, string $subject, int $limit = -1, int $flags = 0) {}
/**
* @param array $input
*

View File

@ -1355,6 +1355,13 @@ class FunctionCallTest extends TestCase
[],
'7.4'
],
'pregSplit' => [
'<?php
/** @return non-empty-list */
function foo(string $s) {
return preg_split("/ /", $s);
}'
],
];
}
@ -1856,6 +1863,14 @@ class FunctionCallTest extends TestCase
}',
'error_message' => 'ArgumentTypeCoercion',
],
'pregSplitNoEmpty' => [
'<?php
/** @return non-empty-list */
function foo(string $s) {
return preg_split("/ /", $s, -1, PREG_SPLIT_NO_EMPTY);
}',
'error_message' => 'InvalidReturnStatement'
],
];
}
}