From ca4a8d9d7447d7be656dc69ced55fb07b304b21f Mon Sep 17 00:00:00 2001 From: Alex Kalineskou Date: Thu, 9 Jun 2022 01:36:32 +0300 Subject: [PATCH 1/2] Add array_udiff to arrayFunctions.stub --- stubs/arrayFunctions.stub | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stubs/arrayFunctions.stub b/stubs/arrayFunctions.stub index 3f98bf62ca..8c438327cd 100644 --- a/stubs/arrayFunctions.stub +++ b/stubs/arrayFunctions.stub @@ -48,3 +48,16 @@ function uksort( array &$one, callable $two ): bool {} + +/** + * @template T of mixed + * + * @param array $one + * @param array $two + * @param callable(T, T): int<-1, 1> $three + */ +function array_udiff( + array $one, + array $two, + callable $three +): int {} From e4a0316e61268b6f5c40e5e2aea31a1cdffb8f4a Mon Sep 17 00:00:00 2001 From: Alex Kalineskou Date: Thu, 9 Jun 2022 14:18:43 +0300 Subject: [PATCH 2/2] Add test --- .../CallToFunctionParametersRuleTest.php | 26 ++++++++++++++ .../Rules/Functions/data/array_udiff.php | 34 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/PHPStan/Rules/Functions/data/array_udiff.php diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index c7d2e698e7..338991338d 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -618,6 +618,32 @@ public function testArrayWalkArrowFunctionCallback(): void ]); } + 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, null given.', + 20, + ], + [ + 'Parameter #2 $arr2 of function array_udiff expects array, 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, + ], + ]); + } + public function testPregReplaceCallback(): void { $this->analyse([__DIR__ . '/data/preg_replace_callback.php'], [ diff --git a/tests/PHPStan/Rules/Functions/data/array_udiff.php b/tests/PHPStan/Rules/Functions/data/array_udiff.php new file mode 100644 index 0000000000..b3a72cf4d7 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/array_udiff.php @@ -0,0 +1,34 @@ + $b; + }, +); +