Skip to content

Commit

Permalink
Add array_udiff to arrayFunctions.stub
Browse files Browse the repository at this point in the history
  • Loading branch information
akalineskou committed Jun 9, 2022
1 parent ef8c7c3 commit 98a3b07
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stubs/arrayFunctions.stub
Expand Up @@ -48,3 +48,16 @@ function uksort(
array &$one,
callable $two
): bool {}

/**
* @template T of mixed
*
* @param array<T> $one
* @param array<T> $two
* @param callable(T, T): int<-1, 1> $three
*/
function array_udiff(
array $one,
array $two,
callable $three
): int {}
26 changes: 26 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Expand Up @@ -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<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,
],
]);
}

public function testPregReplaceCallback(): void
{
$this->analyse([__DIR__ . '/data/preg_replace_callback.php'], [
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Rules/Functions/data/array_udiff.php
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

array_udiff(
[1,2,3],
[4,5,6],
function(string $a, string $b): string {
return $a . $b;
},
);

array_udiff(
[1,2,3],
[4,5,6],
function(int $a, int $b): string {
return $a . $b;
},
);

array_udiff(
null,
null,
function(string $a, int $b): string {
return $a . $b;
},
);

array_udiff(
[25,26],
[26,27],
static function(int $a, int $b): int {
return $a <=> $b;
},
);

0 comments on commit 98a3b07

Please sign in to comment.