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 generic typings to array_uintersect #3806

Open
wants to merge 5 commits into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions stubs/arrayFunctions.stub
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ function array_udiff(
callable $three
): int {}

/**
* @template T
* @param array<T> $one
* @param array<T> $two
* @param callable(T, T): int $three
*/
function array_uintersect(
array $one,
array $two,
callable $three
): int {}

/**
* @param array<array-key, mixed> $value
* @return ($value is list ? true : false)
Expand Down
26 changes: 26 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,32 @@ public function testArrayUdiffCallback(): void
]);
}

public function testArrayUintersectCallback(): void
{
$this->analyse([__DIR__ . '/data/array_uintersect.php'], [
[
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(string, string): string given.',
6,
],
[
'Parameter #3 $data_compare_func of function array_uintersect expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(int, int): (literal-string&lowercase-string&non-falsy-string&numeric-string&uppercase-string) given.',
14,
],
[
'Parameter #1 $arr1 of function array_uintersect expects array<string>, null given.',
20,
],
[
'Parameter #2 $arr2 of function array_uintersect expects array<string>, null given.',
21,
],
[
'Parameter #3 $data_compare_func of function array_uintersect expects callable(string, string): int, Closure(string, int): non-empty-string given.',
22,
],
]);
}

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

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

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

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

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

array_uintersect(
["25","26"],
["26","27"],
'strcasecmp',
);
Loading