Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add array_udiff to arrayFunctions.stub #1407

Merged
merged 2 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
},
);