Skip to content

Commit

Permalink
Rename cmp_function parameters to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 16, 2021
1 parent 3a773ac commit 27a5d0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 59 deletions.
18 changes: 9 additions & 9 deletions resources/functionMap.php
Expand Up @@ -346,8 +346,8 @@
'ArrayIterator::seek' => ['void', 'position'=>'int'],
'ArrayIterator::serialize' => ['string'],
'ArrayIterator::setFlags' => ['void', 'flags'=>'string'],
'ArrayIterator::uasort' => ['void', 'cmp_function'=>'callable(mixed,mixed):int'],
'ArrayIterator::uksort' => ['void', 'cmp_function'=>'callable(array-key,array-key):int'],
'ArrayIterator::uasort' => ['void', 'callback'=>'callable(mixed,mixed):int'],
'ArrayIterator::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'ArrayIterator::unserialize' => ['void', 'serialized'=>'string'],
'ArrayIterator::valid' => ['bool'],
'ArrayObject::__construct' => ['void', 'input='=>'array|object', 'flags='=>'int', 'iterator_class='=>'string'],
Expand All @@ -369,8 +369,8 @@
'ArrayObject::serialize' => ['string'],
'ArrayObject::setFlags' => ['void', 'flags'=>'int'],
'ArrayObject::setIteratorClass' => ['void', 'iterator_class'=>'string'],
'ArrayObject::uasort' => ['void', 'cmp_function'=>'callable'],
'ArrayObject::uksort' => ['void', 'cmp_function'=>'callable(array-key,array-key):int'],
'ArrayObject::uasort' => ['void', 'callback'=>'callable'],
'ArrayObject::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'ArrayObject::unserialize' => ['void', 'serialized'=>'string'],
'arsort' => ['bool', '&rw_array_arg'=>'array', 'sort_flags='=>'int'],
'asin' => ['float', 'number'=>'float'],
Expand Down Expand Up @@ -9174,8 +9174,8 @@
'RecursiveArrayIterator::seek' => ['void', 'position'=>'int'],
'RecursiveArrayIterator::serialize' => ['string'],
'RecursiveArrayIterator::setFlags' => ['void', 'flags'=>'string'],
'RecursiveArrayIterator::uasort' => ['void', 'cmp_function'=>'callable(mixed,mixed):int'],
'RecursiveArrayIterator::uksort' => ['void', 'cmp_function'=>'callable(array-key,array-key):int'],
'RecursiveArrayIterator::uasort' => ['void', 'callback'=>'callable(mixed,mixed):int'],
'RecursiveArrayIterator::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'RecursiveArrayIterator::unserialize' => ['string', 'serialized'=>'string'],
'RecursiveArrayIterator::valid' => ['bool'],
'RecursiveCachingIterator::__construct' => ['void', 'iterator'=>'Iterator', 'flags'=>''],
Expand Down Expand Up @@ -12565,7 +12565,7 @@
'TypeError::getPrevious' => ['Throwable|TypeError|null'],
'TypeError::getTrace' => ['array'],
'TypeError::getTraceAsString' => ['string'],
'uasort' => ['bool', '&rw_array_arg'=>'array', 'cmp_function'=>'callable(mixed,mixed):int'],
'uasort' => ['bool', '&rw_array_arg'=>'array', 'callback'=>'callable(mixed,mixed):int'],
'ucfirst' => ['string', 'str'=>'string'],
'UConverter::__construct' => ['void', 'destination_encoding'=>'string', 'source_encoding='=>'string'],
'UConverter::convert' => ['string', 'str'=>'string', 'reverse='=>'bool'],
Expand Down Expand Up @@ -12614,7 +12614,7 @@
'ui\draw\text\font\fontfamilies' => ['array'],
'ui\quit' => ['void'],
'ui\run' => ['void', 'flags='=>'int'],
'uksort' => ['bool', '&rw_array_arg'=>'array', 'cmp_function'=>'callable(array-key,array-key):int'],
'uksort' => ['bool', '&rw_array_arg'=>'array', 'callback'=>'callable(array-key,array-key):int'],
'umask' => ['int', 'mask='=>'int'],
'UnderflowException::__clone' => ['void'],
'UnderflowException::__construct' => ['void', 'message='=>'string', 'code='=>'int', 'previous='=>'(?Throwable)|(?UnderflowException)'],
Expand Down Expand Up @@ -12694,7 +12694,7 @@
'urlencode' => ['string', 'str'=>'string'],
'use_soap_error_handler' => ['bool', 'handler='=>'bool'],
'usleep' => ['void', 'micro_seconds'=>'int'],
'usort' => ['bool', '&rw_array_arg'=>'array', 'cmp_function'=>'callable(mixed,mixed):int'],
'usort' => ['bool', '&rw_array_arg'=>'array', 'callback'=>'callable(mixed,mixed):int'],
'utf8_decode' => ['string', 'data'=>'string'],
'utf8_encode' => ['string', 'data'=>'string'],
'V8Js::__construct' => ['void', 'object_name='=>'string', 'variables='=>'array', 'extensions='=>'array', 'report_uncaught_exceptions='=>'bool', 'snapshot_blob='=>'string'],
Expand Down
Expand Up @@ -220,7 +220,7 @@ public function dataMethods(): array
'uasort',
[
[
'name' => 'cmp_function',
'name' => 'callback',
'optional' => false,
'type' => new CallableType([
new NativeParameterReflection('', false, new MixedType(true), PassedByReference::createNo(), false, null),
Expand Down
57 changes: 8 additions & 49 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Expand Up @@ -630,16 +630,9 @@ public function testArrayWalkArrowFunctionCallback(): void

public function testUasortCallback(): void
{
$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/uasort.php'], [
[
sprintf(
'Parameter #2 $%s of function uasort expects callable(int, int): int, Closure(string, string): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function uasort expects callable(int, int): int, Closure(string, string): 1 given.',
7,
],
]);
Expand All @@ -650,33 +643,20 @@ public function testUasortArrowFunctionCallback(): void
if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 7.4.');
}
$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/uasort_arrow.php'], [
[
sprintf(
'Parameter #2 $%s of function uasort expects callable(int, int): int, Closure(string, string): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function uasort expects callable(int, int): int, Closure(string, string): 1 given.',
7,
],
]);
}

public function testUsortCallback(): void
{
$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/usort.php'], [
[
sprintf(
'Parameter #2 $%s of function usort expects callable(int, int): int, Closure(string, string): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function usort expects callable(int, int): int, Closure(string, string): 1 given.',
14,
],
]);
Expand All @@ -688,37 +668,23 @@ public function testUsortArrowFunctionCallback(): void
$this->markTestSkipped('Test requires PHP 7.4.');
}

$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/usort_arrow.php'], [
[
sprintf(
'Parameter #2 $%s of function usort expects callable(int, int): int, Closure(string, string): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function usort expects callable(int, int): int, Closure(string, string): 1 given.',
14,
],
]);
}

public function testUksortCallback(): void
{
$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/uksort.php'], [
[
sprintf(
'Parameter #2 $%s of function uksort expects callable(string, string): int, Closure(stdClass, stdClass): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function uksort expects callable(string, string): int, Closure(stdClass, stdClass): 1 given.',
14,
],
[
sprintf('Parameter #2 $%s of function uksort expects callable(int, int): int, Closure(string, string): 1 given.', $paramTwoName),
'Parameter #2 $callback of function uksort expects callable(int, int): int, Closure(string, string): 1 given.',
50,
],
]);
Expand All @@ -730,20 +696,13 @@ public function testUksortArrowFunctionCallback(): void
$this->markTestSkipped('Test requires PHP 7.4.');
}

$paramTwoName = PHP_VERSION_ID >= 80000
? 'callback'
: 'cmp_function';

$this->analyse([__DIR__ . '/data/uksort_arrow.php'], [
[
sprintf(
'Parameter #2 $%s of function uksort expects callable(string, string): int, Closure(stdClass, stdClass): 1 given.',
$paramTwoName
),
'Parameter #2 $callback of function uksort expects callable(string, string): int, Closure(stdClass, stdClass): 1 given.',
14,
],
[
sprintf('Parameter #2 $%s of function uksort expects callable(int, int): int, Closure(string, string): 1 given.', $paramTwoName),
'Parameter #2 $callback of function uksort expects callable(int, int): int, Closure(string, string): 1 given.',
44,
],
]);
Expand Down

0 comments on commit 27a5d0f

Please sign in to comment.