mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Soften definition of purity to allow functions that return by-ref output
This commit is contained in:
parent
4cac8cd70f
commit
0fc8c9a9bb
@ -346,6 +346,11 @@ class Functions
|
||||
return false;
|
||||
}
|
||||
|
||||
// $matches is basically the (conditional) output of these functions
|
||||
if ($function_id === 'preg_match' || $function_id === 'preg_match_all') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$function_callable = \Psalm\Internal\Codebase\CallMap::getCallableFromCallMapById(
|
||||
$codebase,
|
||||
$function_id,
|
||||
@ -356,12 +361,6 @@ class Functions
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($function_callable->params as $i => $param) {
|
||||
if ($param->by_ref && isset($args[$i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
* @param bool $strict
|
||||
*
|
||||
* @return array<int, T>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_keys(array $arr, $search_value = null, bool $strict = false)
|
||||
{
|
||||
@ -18,6 +19,7 @@ function array_keys(array $arr, $search_value = null, bool $strict = false)
|
||||
* @param array<mixed, T> $arr
|
||||
*
|
||||
* @return array<int, T>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_values(array $arr)
|
||||
{
|
||||
@ -31,6 +33,7 @@ function array_values(array $arr)
|
||||
* @param int $sort_flags
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_unique(array $arr, int $sort_flags = 0)
|
||||
{
|
||||
@ -46,6 +49,7 @@ function array_unique(array $arr, int $sort_flags = 0)
|
||||
* @param array|null $arr4
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_intersect(array $arr, array $arr2, array $arr3 = null, array $arr4 = null)
|
||||
{
|
||||
@ -61,6 +65,7 @@ function array_intersect(array $arr, array $arr2, array $arr3 = null, array $arr
|
||||
* @param array|null $arr4
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_intersect_key(array $arr, array $arr2, array $arr3 = null, array $arr4 = null)
|
||||
{
|
||||
@ -75,6 +80,7 @@ function array_intersect_key(array $arr, array $arr2, array $arr3 = null, array
|
||||
*
|
||||
* @return array<TKey, TValue>|false
|
||||
* @psalm-ignore-falsable-return
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_combine(array $arr, array $arr2)
|
||||
{
|
||||
@ -90,6 +96,7 @@ function array_combine(array $arr, array $arr2)
|
||||
* @param array|null $arr4
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_diff(array $arr, array $arr2, array $arr3 = null, array $arr4 = null)
|
||||
{
|
||||
@ -105,6 +112,7 @@ function array_diff(array $arr, array $arr2, array $arr3 = null, array $arr4 = n
|
||||
* @param array|null $arr4
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_diff_key(array $arr, array $arr2, array $arr3 = null, array $arr4 = null)
|
||||
{
|
||||
@ -117,6 +125,7 @@ function array_diff_key(array $arr, array $arr2, array $arr3 = null, array $arr4
|
||||
* @param array<TKey, TValue> $arr
|
||||
*
|
||||
* @return array<TValue, TKey>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_flip(array $arr)
|
||||
{
|
||||
@ -129,6 +138,7 @@ function array_flip(array $arr)
|
||||
*
|
||||
* @return TKey|null
|
||||
* @psalm-ignore-nullable-return
|
||||
* @psalm-pure
|
||||
*/
|
||||
function key($arr)
|
||||
{
|
||||
@ -140,6 +150,7 @@ function key($arr)
|
||||
* @param TValue $value
|
||||
*
|
||||
* @return array<int, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_fill(int $start_index, int $num, $value) : array
|
||||
{
|
||||
@ -153,6 +164,7 @@ function array_fill(int $start_index, int $num, $value) : array
|
||||
* @param bool $strict
|
||||
*
|
||||
* @return T|false
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_search($needle, array $haystack, bool $strict = false)
|
||||
{
|
||||
@ -164,6 +176,7 @@ function array_search($needle, array $haystack, bool $strict = false)
|
||||
* @param array<mixed,T> $arr
|
||||
* @param callable(T,T):int $callback
|
||||
* @param-out array<int,T> $arr
|
||||
* @psalm-pure
|
||||
*/
|
||||
function usort(array &$arr, callable $callback): bool
|
||||
{
|
||||
@ -175,6 +188,7 @@ function usort(array &$arr, callable $callback): bool
|
||||
* @param array<string, T> $arr
|
||||
*
|
||||
* @return array<string, T>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_change_key_case(array $arr, int $case = CASE_LOWER)
|
||||
{
|
||||
@ -186,6 +200,7 @@ function array_change_key_case(array $arr, int $case = CASE_LOWER)
|
||||
* @param array<array-key, T> $arr
|
||||
*
|
||||
* @return array<int, array<array-key, T>>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_chunk(array $arr, int $size, bool $preserve_keys = false)
|
||||
{
|
||||
@ -198,6 +213,7 @@ function array_chunk(array $arr, int $size, bool $preserve_keys = false)
|
||||
* @param array<TKey, mixed> $search
|
||||
*
|
||||
* @return bool
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_key_exists($key, array $search) : bool
|
||||
{
|
||||
@ -211,6 +227,7 @@ function array_key_exists($key, array $search) : bool
|
||||
* @param array<TKey, TValue> ...$arr2
|
||||
*
|
||||
* @return array<TKey, TValue>
|
||||
* @psalm-pure
|
||||
*/
|
||||
function array_merge_recursive(array $arr, array ...$arr2)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user