From 27a5d0f10b1b9b65c3165ddae500e40b769d1301 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 16 Sep 2021 16:54:07 +0200 Subject: [PATCH] Rename cmp_function parameters to callback --- resources/functionMap.php | 18 +++--- .../Php8SignatureMapProviderTest.php | 2 +- .../CallToFunctionParametersRuleTest.php | 57 +++---------------- 3 files changed, 18 insertions(+), 59 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index a52dbdbeeb..b4a7943555 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -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'], @@ -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'], @@ -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'=>''], @@ -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'], @@ -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)'], @@ -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'], diff --git a/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php b/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php index 390ad5a955..eab83934f2 100644 --- a/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php +++ b/tests/PHPStan/Reflection/SignatureMap/Php8SignatureMapProviderTest.php @@ -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), diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 0714cd96ce..cfdaaad4ba 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -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, ], ]); @@ -650,16 +643,10 @@ 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, ], ]); @@ -667,16 +654,9 @@ public function testUasortArrowFunctionCallback(): void 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, ], ]); @@ -688,16 +668,9 @@ 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, ], ]); @@ -705,20 +678,13 @@ public function testUsortArrowFunctionCallback(): void 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, ], ]); @@ -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, ], ]);