Add array_udiff to arrayFunctions.stub#1407
Conversation
|
Please add a regression test in CallToFunctionParametersRuleTest with a code sample from phpstan/phpstan#6105 (and maybe add another call that shows that wrong closure will be reported). Thanks! |
|
@ondrejmirtes Before I push the test and run the whole suite again, would something like this work?
<?php declare(strict_types = 1);
array_udiff(
[1,2,3],
[4,5,6],
function(string $a, string $b): string { // line 6
return $a . $b;
},
);
array_udiff(
[1,2,3],
[4,5,6],
function(int $a, int $b): string { // line 14
return $a . $b;
},
);
array_udiff(
null, // line 20
null, // line 21
function(string $a, int $b): string { // line 22
return $a . $b;
},
);
array_udiff(
[25,26],
[26,27],
static function(int $a, int $b): int {
return $a <=> $b;
},
);public function testArrayUdiffCallback(): void
{
$this->analyse([__DIR__ . '/data/array_udiff.php'], [
[
'Parameter #3 $data_comp_func of function array_udiff expects callable(int, int): int<-1, 1>, Closure(string, string): string given.',
6,
],
[
'Parameter #3 $data_comp_func of function array_udiff expects callable(int, int): int<-1, 1>, Closure(int, int): non-empty-string given.',
14,
],
[
'Parameter #1 $arr1 of function array_udiff expects array<string>, null given.',
20,
],
[
'Parameter #2 $arr2 of function array_udiff expects array<string>, null given.',
21,
],
[
'Parameter #3 $data_comp_func of function array_udiff expects callable(string, string): int<-1, 1>, Closure(string, int): non-empty-string given.',
22,
],
]);
} |
|
Just push it and I'll see if it makes sense. |
|
Thank you! |
|
@akalineskou @ondrejmirtes Does this also fix https://phpstan.org/r/e5210925-d640-4f76-a0e0-19ef3825d0f3 ? |
|
@bytestream These compare functions should all be updated to note they also return |
|
I'm not sure if this instead belongs to a new issue, but shouldn't the callback of an From https://www.php.net/manual/en/function.array-udiff.php:
There is nothing that restricts the callback to return |
Closes phpstan/phpstan#6105