Skip to content

Correct and improve return types for sorting functions #906

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
44 changes: 22 additions & 22 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@
'ArrayAccess::offsetUnset' => ['void', 'offset'=>'mixed'],
'ArrayIterator::__construct' => ['void', 'array='=>'array|object', 'flags='=>'int'],
'ArrayIterator::append' => ['void', 'value'=>'mixed'],
'ArrayIterator::asort' => ['void'],
'ArrayIterator::asort' => ['true'],
'ArrayIterator::count' => ['0|positive-int'],
'ArrayIterator::current' => ['mixed'],
'ArrayIterator::getArrayCopy' => ['array'],
'ArrayIterator::getFlags' => ['int'],
'ArrayIterator::key' => ['int|string|false'],
'ArrayIterator::ksort' => ['void'],
'ArrayIterator::natcasesort' => ['void'],
'ArrayIterator::natsort' => ['void'],
'ArrayIterator::ksort' => ['true'],
'ArrayIterator::natcasesort' => ['true'],
'ArrayIterator::natsort' => ['true'],
'ArrayIterator::next' => ['void'],
'ArrayIterator::offsetExists' => ['bool', 'index'=>'string|int|bool|null'],
'ArrayIterator::offsetGet' => ['mixed', 'index'=>'string|int|bool|null'],
Expand All @@ -345,31 +345,31 @@
'ArrayIterator::seek' => ['void', 'position'=>'int'],
'ArrayIterator::serialize' => ['string'],
'ArrayIterator::setFlags' => ['void', 'flags'=>'string'],
'ArrayIterator::uasort' => ['void', 'callback'=>'callable(mixed,mixed):int'],
'ArrayIterator::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'ArrayIterator::uasort' => ['true', 'callback'=>'callable(mixed,mixed):int'],
'ArrayIterator::uksort' => ['true', '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='=>'class-string'],
'ArrayObject::append' => ['void', 'value'=>'mixed'],
'ArrayObject::asort' => ['void'],
'ArrayObject::asort' => ['true'],
'ArrayObject::count' => ['0|positive-int'],
'ArrayObject::exchangeArray' => ['array', 'ar'=>'mixed'],
'ArrayObject::getArrayCopy' => ['array'],
'ArrayObject::getFlags' => ['int'],
'ArrayObject::getIterator' => ['ArrayIterator'],
'ArrayObject::getIteratorClass' => ['string'],
'ArrayObject::ksort' => ['void'],
'ArrayObject::natcasesort' => ['void'],
'ArrayObject::natsort' => ['void'],
'ArrayObject::ksort' => ['true'],
'ArrayObject::natcasesort' => ['true'],
'ArrayObject::natsort' => ['true'],
'ArrayObject::offsetExists' => ['bool', 'index'=>'mixed'],
'ArrayObject::offsetGet' => ['mixed', 'index'=>'mixed'],
'ArrayObject::offsetSet' => ['void', 'index'=>'mixed', 'newval'=>'mixed'],
'ArrayObject::offsetUnset' => ['void', 'index'=>'mixed'],
'ArrayObject::serialize' => ['string'],
'ArrayObject::setFlags' => ['void', 'flags'=>'int'],
'ArrayObject::setIteratorClass' => ['void', 'iterator_class'=>'string'],
'ArrayObject::uasort' => ['void', 'callback'=>'callable'],
'ArrayObject::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'ArrayObject::uasort' => ['true', 'callback'=>'callable'],
'ArrayObject::uksort' => ['true', '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 @@ -7446,8 +7446,8 @@
'MysqlndUhPreparedStatement::__construct' => ['void'],
'MysqlndUhPreparedStatement::execute' => ['bool', 'statement'=>'mysqlnd_prepared_statement'],
'MysqlndUhPreparedStatement::prepare' => ['bool', 'statement'=>'mysqlnd_prepared_statement', 'query'=>'string'],
'natcasesort' => ['bool', '&rw_array_arg'=>'array'],
'natsort' => ['bool', '&rw_array_arg'=>'array'],
'natcasesort' => ['?bool', '&rw_array_arg'=>'array'],
'natsort' => ['?bool', '&rw_array_arg'=>'array'],
'ncurses_addch' => ['int', 'ch'=>'int'],
'ncurses_addchnstr' => ['int', 's'=>'string', 'n'=>'int'],
'ncurses_addchstr' => ['int', 's'=>'string'],
Expand Down Expand Up @@ -9149,17 +9149,17 @@
'rectObj::setextent' => ['void', 'minx'=>'float', 'miny'=>'float', 'maxx'=>'float', 'maxy'=>'float'],
'RecursiveArrayIterator::__construct' => ['void', 'array='=>'array|object', 'flags='=>'int'],
'RecursiveArrayIterator::append' => ['void', 'value'=>'mixed'],
'RecursiveArrayIterator::asort' => ['void'],
'RecursiveArrayIterator::asort' => ['true'],
'RecursiveArrayIterator::count' => ['0|positive-int'],
'RecursiveArrayIterator::current' => ['mixed'],
'RecursiveArrayIterator::getArrayCopy' => ['array'],
'RecursiveArrayIterator::getChildren' => ['RecursiveArrayIterator'],
'RecursiveArrayIterator::getFlags' => ['void'],
'RecursiveArrayIterator::hasChildren' => ['bool'],
'RecursiveArrayIterator::key' => ['false|int|string'],
'RecursiveArrayIterator::ksort' => ['void'],
'RecursiveArrayIterator::natcasesort' => ['void'],
'RecursiveArrayIterator::natsort' => ['void'],
'RecursiveArrayIterator::ksort' => ['true'],
'RecursiveArrayIterator::natcasesort' => ['true'],
'RecursiveArrayIterator::natsort' => ['true'],
'RecursiveArrayIterator::next' => ['void'],
'RecursiveArrayIterator::offsetExists' => ['void', 'index'=>'string'],
'RecursiveArrayIterator::offsetGet' => ['mixed', 'index'=>'string'],
Expand All @@ -9169,8 +9169,8 @@
'RecursiveArrayIterator::seek' => ['void', 'position'=>'int'],
'RecursiveArrayIterator::serialize' => ['string'],
'RecursiveArrayIterator::setFlags' => ['void', 'flags'=>'string'],
'RecursiveArrayIterator::uasort' => ['void', 'callback'=>'callable(mixed,mixed):int'],
'RecursiveArrayIterator::uksort' => ['void', 'callback'=>'callable(array-key,array-key):int'],
'RecursiveArrayIterator::uasort' => ['true', 'callback'=>'callable(mixed,mixed):int'],
'RecursiveArrayIterator::uksort' => ['true', '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 @@ -12560,7 +12560,7 @@
'TypeError::getPrevious' => ['Throwable|TypeError|null'],
'TypeError::getTrace' => ['array{function:string,line?:int,file?:string,class?:class-string,type?:\'::\'|\'->\',args?:mixed[],object?:object}'],
'TypeError::getTraceAsString' => ['string'],
'uasort' => ['bool', '&rw_array_arg'=>'array', 'callback'=>'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 @@ -12609,7 +12609,7 @@
'ui\draw\text\font\fontfamilies' => ['array'],
'ui\quit' => ['void'],
'ui\run' => ['void', 'flags='=>'int'],
'uksort' => ['bool', '&rw_array_arg'=>'array', 'callback'=>'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
11 changes: 11 additions & 0 deletions resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
return [
'new' => [
'array_combine' => ['associative-array', 'keys'=>'string[]|int[]', 'values'=>'array'],
'arsort' => ['true', '&array'=>'array', 'flags='=>'int'],
'asort' => ['true', '&array'=>'array', 'flags='=>'int'],
'bcdiv' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'],
'bcmod' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'],
'bcpowmod' => ['string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'],
Expand Down Expand Up @@ -72,11 +74,15 @@
'imagejpeg' => ['bool', 'im'=>'GdImage', 'filename='=>'string|resource|null', 'quality='=>'int'],
'imagerotate' => ['false|object', 'src_im'=>'resource', 'angle'=>'float', 'bgdcolor'=>'int', 'ignoretransparent='=>'int'],
'imagescale' => ['false|object', 'im'=>'resource', 'new_width'=>'int', 'new_height='=>'int', 'method='=>'int'],
'krsort' => ['true', '&array'=>'array', 'flags='=>'int'],
'ksort' => ['true', '&array'=>'array', 'flags='=>'int'],
'ldap_set_rebind_proc' => ['bool', 'ldap'=>'resource', 'callback'=>'?callable'],
'mb_decode_numericentity' => ['string|false', 'string'=>'string', 'convmap'=>'array', 'encoding='=>'string'],
'mb_str_split' => ['non-empty-array<int,string>', 'str'=>'string', 'split_length='=>'positive-int', 'encoding='=>'string'],
'mb_strlen' => ['0|positive-int', 'str'=>'string', 'encoding='=>'string'],
'mktime' => ['int|false', 'hour'=>'int', 'minute='=>'int', 'second='=>'int', 'month='=>'int', 'day='=>'int', 'year='=>'int'],
'natcasesort' => ['true', '&array'=>'array'],
'natsort' => ['true', '&array'=>'array'],
'odbc_exec' => ['resource|false', 'connection_id'=>'resource', 'query'=>'string'],
'parse_str' => ['void', 'encoded_string'=>'string', '&w_result'=>'array'],
'password_hash' => ['string', 'password'=>'string', 'algo'=>'string|int|null', 'options='=>'array'],
Expand All @@ -87,10 +93,12 @@
'PhpToken::getTokenName' => ['string'],
'preg_match_all' => ['0|positive-int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'array', 'flags='=>'int', 'offset='=>'int'],
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', 'process'=>'resource'],
'rsort' => ['true', '&array'=>'array', 'flags='=>'int'],
'set_error_handler' => ['?callable', 'callback'=>'null|callable(int,string,string,int):bool', 'error_types='=>'int'],
'socket_addrinfo_lookup' => ['AddressInfo[]', 'node'=>'string', 'service='=>'mixed', 'hints='=>'array'],
'socket_select' => ['int|false', '&rw_read'=>'Socket[]|null', '&rw_write'=>'Socket[]|null', '&rw_except'=>'Socket[]|null', 'seconds'=>'int|null', 'microseconds='=>'int'],
'sodium_crypto_aead_chacha20poly1305_ietf_decrypt' => ['string|false', 'confidential_message'=>'string', 'public_message'=>'string', 'nonce'=>'string', 'key'=>'string'],
'sort' => ['true', '&array'=>'array', 'flags='=>'int'],
'str_contains' => ['bool', 'haystack'=>'string', 'needle'=>'string'],
'str_split' => ['non-empty-array<int,string>', 'str'=>'string', 'split_length='=>'positive-int'],
'str_ends_with' => ['bool', 'haystack'=>'string', 'needle'=>'string'],
Expand All @@ -104,6 +112,9 @@
'strrpos' => ['int|false', 'haystack'=>'string', 'needle'=>'string', 'offset='=>'int'],
'strstr' => ['string|false', 'haystack'=>'string', 'needle'=>'string', 'before_needle='=>'bool'],
'substr' => ['string', 'string'=>'string', 'start'=>'int', 'length='=>'int'],
'uasort' => ['true', '&array'=>'array', 'callback'=>'callable(mixed,mixed):int'],
'uksort' => ['true', '&array'=>'array', 'callback'=>'callable(array-key,array-key):int'],
'usort' => ['true', '&array'=>'array', 'callback'=>'callable(mixed,mixed):int'],
'version_compare' => ['int|bool', 'version1'=>'string', 'version2'=>'string', 'operator='=>'string'],
'xml_parser_create' => ['XMLParser', 'encoding='=>'string'],
'xml_parser_create_ns' => ['XMLParser', 'encoding='=>'string', 'sep='=>'string'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use PHPStan\Type\VoidType;
use function array_map;
use function array_merge;
use function count;
Expand Down Expand Up @@ -225,7 +224,7 @@ public function dataMethods(): array
'variadic' => false,
],
],
new VoidType(),
new ConstantBooleanType(true),
new MixedType(),
false,
],
Expand All @@ -245,7 +244,7 @@ public function dataMethods(): array
'variadic' => false,
],
],
new VoidType(),
new ConstantBooleanType(true),
new MixedType(), // todo - because uasort is not found in file with RecursiveArrayIterator
false,
],
Expand Down