From 36dfeed7743ee9b116d5dde9da099de01abec1c9 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 4 Sep 2021 23:39:02 +0300 Subject: [PATCH 1/2] Converted ftp functions to use link object instead of a resource Fixes vimeo/psalm#6403 --- dictionaries/CallMap.php | 72 +++++++------- dictionaries/CallMap_81_delta.php | 151 +++++++++++++++++++++++++++++- 2 files changed, 183 insertions(+), 40 deletions(-) diff --git a/dictionaries/CallMap.php b/dictionaries/CallMap.php index cadac23ab83..21eb380c745 100644 --- a/dictionaries/CallMap.php +++ b/dictionaries/CallMap.php @@ -3327,42 +3327,42 @@ 'fstat' => ['array|false', 'stream'=>'resource'], 'ftell' => ['int|false', 'stream'=>'resource'], 'ftok' => ['int', 'filename'=>'string', 'project_id'=>'string'], -'ftp_alloc' => ['bool', 'ftp'=>'resource', 'size'=>'int', '&w_response='=>'string'], -'ftp_append' => ['bool', 'ftp'=>'resource', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int'], -'ftp_cdup' => ['bool', 'ftp'=>'resource'], -'ftp_chdir' => ['bool', 'ftp'=>'resource', 'directory'=>'string'], -'ftp_chmod' => ['int|false', 'ftp'=>'resource', 'permissions'=>'int', 'filename'=>'string'], -'ftp_close' => ['bool', 'ftp'=>'resource'], -'ftp_connect' => ['resource|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'], -'ftp_delete' => ['bool', 'ftp'=>'resource', 'filename'=>'string'], -'ftp_exec' => ['bool', 'ftp'=>'resource', 'command'=>'string'], -'ftp_fget' => ['bool', 'ftp'=>'resource', 'stream'=>'resource', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_fput' => ['bool', 'ftp'=>'resource', 'remote_filename'=>'string', 'stream'=>'resource', 'mode='=>'int', 'offset='=>'int'], -'ftp_get' => ['bool', 'ftp'=>'resource', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_get_option' => ['mixed|false', 'ftp'=>'resource', 'option'=>'int'], -'ftp_login' => ['bool', 'ftp'=>'resource', 'username'=>'string', 'password'=>'string'], -'ftp_mdtm' => ['int', 'ftp'=>'resource', 'filename'=>'string'], -'ftp_mkdir' => ['string|false', 'ftp'=>'resource', 'directory'=>'string'], -'ftp_mlsd' => ['array|false', 'ftp'=>'resource', 'directory'=>'string'], -'ftp_nb_continue' => ['int', 'ftp'=>'resource'], -'ftp_nb_fget' => ['int', 'ftp'=>'resource', 'stream'=>'resource', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_nb_fput' => ['int', 'ftp'=>'resource', 'remote_filename'=>'string', 'stream'=>'resource', 'mode='=>'int', 'offset='=>'int'], -'ftp_nb_get' => ['int', 'ftp'=>'resource', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_nb_put' => ['int', 'ftp'=>'resource', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_nlist' => ['array|false', 'ftp'=>'resource', 'directory'=>'string'], -'ftp_pasv' => ['bool', 'ftp'=>'resource', 'enable'=>'bool'], -'ftp_put' => ['bool', 'ftp'=>'resource', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], -'ftp_pwd' => ['string|false', 'ftp'=>'resource'], -'ftp_quit' => ['bool', 'ftp'=>'resource'], -'ftp_raw' => ['array', 'ftp'=>'resource', 'command'=>'string'], -'ftp_rawlist' => ['array|false', 'ftp'=>'resource', 'directory'=>'string', 'recursive='=>'bool'], -'ftp_rename' => ['bool', 'ftp'=>'resource', 'from'=>'string', 'to'=>'string'], -'ftp_rmdir' => ['bool', 'ftp'=>'resource', 'directory'=>'string'], -'ftp_set_option' => ['bool', 'ftp'=>'resource', 'option'=>'int', 'value'=>'mixed'], -'ftp_site' => ['bool', 'ftp'=>'resource', 'command'=>'string'], -'ftp_size' => ['int', 'ftp'=>'resource', 'filename'=>'string'], -'ftp_ssl_connect' => ['resource|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'], -'ftp_systype' => ['string|false', 'ftp'=>'resource'], +'ftp_alloc' => ['bool', 'ftp'=>'FTP\Connection', 'size'=>'int', '&w_response='=>'string'], +'ftp_append' => ['bool', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int'], +'ftp_cdup' => ['bool', 'ftp'=>'FTP\Connection'], +'ftp_chdir' => ['bool', 'ftp'=>'FTP\Connection', 'directory'=>'string'], +'ftp_chmod' => ['int|false', 'ftp'=>'FTP\Connection', 'permissions'=>'int', 'filename'=>'string'], +'ftp_close' => ['bool', 'ftp'=>'FTP\Connection'], +'ftp_connect' => ['FTP\Connection|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'], +'ftp_delete' => ['bool', 'ftp'=>'FTP\Connection', 'filename'=>'string'], +'ftp_exec' => ['bool', 'ftp'=>'FTP\Connection', 'command'=>'string'], +'ftp_fget' => ['bool', 'ftp'=>'FTP\Connection', 'stream'=>'FTP\Connection', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_fput' => ['bool', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'FTP\Connection', 'mode='=>'int', 'offset='=>'int'], +'ftp_get' => ['bool', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_get_option' => ['mixed|false', 'ftp'=>'FTP\Connection', 'option'=>'int'], +'ftp_login' => ['bool', 'ftp'=>'FTP\Connection', 'username'=>'string', 'password'=>'string'], +'ftp_mdtm' => ['int', 'ftp'=>'FTP\Connection', 'filename'=>'string'], +'ftp_mkdir' => ['string|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], +'ftp_mlsd' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], +'ftp_nb_continue' => ['int', 'ftp'=>'FTP\Connection'], +'ftp_nb_fget' => ['int', 'ftp'=>'FTP\Connection', 'stream'=>'FTP\Connection', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_nb_fput' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'stream'=>'FTP\Connection', 'mode='=>'int', 'offset='=>'int'], +'ftp_nb_get' => ['int', 'ftp'=>'FTP\Connection', 'local_filename'=>'string', 'remote_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_nb_put' => ['int', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_nlist' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string'], +'ftp_pasv' => ['bool', 'ftp'=>'FTP\Connection', 'enable'=>'bool'], +'ftp_put' => ['bool', 'ftp'=>'FTP\Connection', 'remote_filename'=>'string', 'local_filename'=>'string', 'mode='=>'int', 'offset='=>'int'], +'ftp_pwd' => ['string|false', 'ftp'=>'FTP\Connection'], +'ftp_quit' => ['bool', 'ftp'=>'FTP\Connection'], +'ftp_raw' => ['array', 'ftp'=>'FTP\Connection', 'command'=>'string'], +'ftp_rawlist' => ['array|false', 'ftp'=>'FTP\Connection', 'directory'=>'string', 'recursive='=>'bool'], +'ftp_rename' => ['bool', 'ftp'=>'FTP\Connection', 'from'=>'string', 'to'=>'string'], +'ftp_rmdir' => ['bool', 'ftp'=>'FTP\Connection', 'directory'=>'string'], +'ftp_set_option' => ['bool', 'ftp'=>'FTP\Connection', 'option'=>'int', 'value'=>'mixed'], +'ftp_site' => ['bool', 'ftp'=>'FTP\Connection', 'command'=>'string'], +'ftp_size' => ['int', 'ftp'=>'FTP\Connection', 'filename'=>'string'], +'ftp_ssl_connect' => ['FTP\Connection|false', 'hostname'=>'string', 'port='=>'int', 'timeout='=>'int'], +'ftp_systype' => ['string|false', 'ftp'=>'FTP\Connection'], 'ftruncate' => ['bool', 'stream'=>'resource', 'size'=>'int'], 'func_get_arg' => ['mixed|false', 'position'=>'int'], 'func_get_args' => ['list'], diff --git a/dictionaries/CallMap_81_delta.php b/dictionaries/CallMap_81_delta.php index 62c738e1d41..ae445a38bec 100644 --- a/dictionaries/CallMap_81_delta.php +++ b/dictionaries/CallMap_81_delta.php @@ -16,12 +16,155 @@ */ return [ 'added' => [ - 'array_is_list' => ['bool', 'array'=>'array'], + 'array_is_list' => ['bool', 'array' => 'array'], ], - 'changed' => [ + 'changed' => [ + 'ftp_connect' => [ + 'old' => ['resource|false', 'hostname' => 'string', 'port=' => 'int', 'timeout=' => 'int'], + 'new' => ['FTP\Connection|false', 'hostname' => 'string', 'port=' => 'int', 'timeout=' => 'int'], + ], + 'ftp_ssl_connect' => [ + 'old' => ['resource|false', 'hostname' => 'string', 'port=' => 'int', 'timeout=' => 'int'], + 'new' => ['FTP\Connection|false', 'hostname' => 'string', 'port=' => 'int', 'timeout=' => 'int'], + ], + 'ftp_login' => [ + 'old' => ['bool', 'ftp' => 'resource', 'username' => 'string', 'password' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'username' => 'string', 'password' => 'string'], + ], + 'ftp_pwd' => [ + 'old' => ['string|false', 'ftp' => 'resource'], + 'new' => ['string|false', 'ftp' => 'FTP\Connection'], + ], + 'ftp_cdup' => [ + 'old' => ['bool', 'ftp' => 'resource'], + 'new' => ['bool', 'ftp' => 'FTP\Connection'], + ], + 'ftp_chdir' => [ + 'old' => ['bool', 'ftp' => 'resource', 'directory' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'directory' => 'string'], + ], + 'ftp_exec' => [ + 'old' => ['bool', 'ftp' => 'resource', 'command' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'command' => 'string'], + ], + 'ftp_raw' => [ + 'old' => ['array', 'ftp' => 'resource', 'command' => 'string'], + 'new' => ['array', 'ftp' => 'FTP\Connection', 'command' => 'string'], + ], + 'ftp_mkdir' => [ + 'old' => ['string|false', 'ftp' => 'resource', 'directory' => 'string'], + 'new' => ['string|false', 'ftp' => 'FTP\Connection', 'directory' => 'string'], + ], + 'ftp_rmdir' => [ + 'old' => ['bool', 'ftp' => 'resource', 'directory' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'directory' => 'string'], + ], + 'ftp_chmod' => [ + 'old' => ['int|false', 'ftp' => 'resource', 'permissions' => 'int', 'filename' => 'string'], + 'new' => ['int|false', 'ftp' => 'FTP\Connection', 'permissions' => 'int', 'filename' => 'string'], + ], + 'ftp_alloc' => [ + 'old' => ['bool', 'ftp' => 'resource', 'size' => 'int', '&w_response=' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'size' => 'int', '&w_response=' => 'string'], + ], + 'ftp_nlist' => [ + 'old' => ['array|false', 'ftp' => 'resource', 'directory' => 'string'], + 'new' => ['array|false', 'ftp' => 'FTP\Connection', 'directory' => 'string'], + ], + 'ftp_rawlist' => [ + 'old' => ['array|false', 'ftp' => 'resource', 'directory' => 'string', 'recursive=' => 'bool'], + 'new' => ['array|false', 'ftp' => 'FTP\Connection', 'directory' => 'string', 'recursive=' => 'bool'], + ], + 'ftp_mlsd' => [ + 'old' => ['array|false', 'ftp' => 'resource', 'directory' => 'string'], + 'new' => ['array|false', 'ftp' => 'FTP\Connection', 'directory' => 'string'], + ], + 'ftp_systype' => [ + 'old' => ['string|false', 'ftp' => 'resource'], + 'new' => ['string|false', 'ftp' => 'FTP\Connection'], + ], + 'ftp_fget' => [ + 'old' => ['bool', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'stream' => 'FTP\Connection', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_nb_fget' => [ + 'old' => ['int', 'ftp' => 'resource', 'stream' => 'resource', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'stream' => 'FTP\Connection', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_pasv' => [ + 'old' => ['bool', 'ftp' => 'resource', 'enable' => 'bool'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'enable' => 'bool'], + ], + 'ftp_get' => [ + 'old' => ['bool', 'ftp' => 'resource', 'local_filename' => 'string', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'local_filename' => 'string', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_nb_get' => [ + 'old' => ['int', 'ftp' => 'resource', 'local_filename' => 'string', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'local_filename' => 'string', 'remote_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_nb_continue' => [ + 'old' => ['int', 'ftp' => 'resource'], + 'new' => ['int', 'ftp' => 'FTP\Connection'], + ], + 'ftp_fput' => [ + 'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'FTP\Connection', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_nb_fput' => [ + 'old' => ['int', 'ftp' => 'resource', 'remote_filename' => 'string', 'stream' => 'resource', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'stream' => 'FTP\Connection', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_put' => [ + 'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_append' => [ + 'old' => ['bool', 'ftp' => 'resource', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int'], + ], + 'ftp_nb_put' => [ + 'old' => ['int', 'ftp' => 'resource', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'remote_filename' => 'string', 'local_filename' => 'string', 'mode=' => 'int', 'offset=' => 'int'], + ], + 'ftp_size' => [ + 'old' => ['int', 'ftp' => 'resource', 'filename' => 'string'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'filename' => 'string'], + ], + 'ftp_mdtm' => [ + 'old' => ['int', 'ftp' => 'resource', 'filename' => 'string'], + 'new' => ['int', 'ftp' => 'FTP\Connection', 'filename' => 'string'], + ], + 'ftp_rename' => [ + 'old' => ['bool', 'ftp' => 'resource', 'from' => 'string', 'to' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'from' => 'string', 'to' => 'string'], + ], + 'ftp_delete' => [ + 'old' => ['bool', 'ftp' => 'resource', 'filename' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'filename' => 'string'], + ], + 'ftp_site' => [ + 'old' => ['bool', 'ftp' => 'resource', 'command' => 'string'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'command' => 'string'], + ], + 'ftp_close' => [ + 'old' => ['bool', 'ftp' => 'resource'], + 'new' => ['bool', 'ftp' => 'FTP\Connection'], + ], + 'ftp_quit' => [ + 'old' => ['bool', 'ftp' => 'resource'], + 'new' => ['bool', 'ftp' => 'FTP\Connection'], + ], + 'ftp_set_option' => [ + 'old' => ['bool', 'ftp' => 'resource', 'option' => 'int', 'value' => 'mixed'], + 'new' => ['bool', 'ftp' => 'FTP\Connection', 'option' => 'int', 'value' => 'mixed'], + ], + 'ftp_get_option' => [ + 'old' => ['mixed|false', 'ftp' => 'resource', 'option' => 'int'], + 'new' => ['mixed|false', 'ftp' => 'FTP\Connection', 'option' => 'int'], + ], ], - 'removed' => [ - ], + 'removed' => [], ]; From 08155dcb41c44a2f7af04de4c7d2bef3fa37b581 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 4 Sep 2021 23:44:06 +0300 Subject: [PATCH 2/2] Added `FTP\Connection` class --- stubs/Php81.phpstub | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/stubs/Php81.phpstub b/stubs/Php81.phpstub index 6f4660c1f8c..94697dcdb85 100644 --- a/stubs/Php81.phpstub +++ b/stubs/Php81.phpstub @@ -1,6 +1,11 @@ */ + public static function cases(): array; + } +} -interface UnitEnum { - /** @return non-empty-list */ - public static function cases(): array; +namespace FTP { + final class Connection {} }