From 9e6cbb5b6a4e23736c6482fd1ab56edbba1987aa Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Jan 2020 20:20:52 +0000 Subject: [PATCH 1/4] Internet: fix type information for getURL(), postURL() and simpleCurl() --- src/pocketmine/utils/Internet.php | 14 ++++++++------ src/pocketmine/utils/Utils.php | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 732865c36..56dd8e3c5 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -134,10 +134,11 @@ class Internet{ * GETs an URL using cURL * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * - * @param int $timeout default 10 - * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param array[] $headers reference parameter - * @param int $httpCode reference parameter + * @param int $timeout default 10 + * @param string[] $extraHeaders + * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. + * @param string[] $headers reference parameter + * @param int $httpCode reference parameter * * @return bool|mixed false if an error occurred, mixed data if successful. */ @@ -156,8 +157,9 @@ class Internet{ * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * * @param array|string $args + * @param string[] $extraHeaders * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param array[] $headers reference parameter + * @param string[] $headers reference parameter * @param int $httpCode reference parameter * * @return bool|mixed false if an error occurred, mixed data if successful. @@ -185,7 +187,7 @@ class Internet{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param (callable(resource) : void)|null $onSuccess * - * @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @return array a plain array of three [result body : string, headers : string[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * * @throws InternetException if a cURL error occurs */ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 10ce678eb..46a625341 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -420,10 +420,11 @@ class Utils{ * @deprecated * @see Internet::getURL() * - * @param int $timeout default 10 - * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param array[] $headers reference parameter - * @param int $httpCode reference parameter + * @param int $timeout default 10 + * @param string[] $extraHeaders + * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. + * @param string[] $headers reference parameter + * @param int $httpCode reference parameter * * @return bool|mixed false if an error occurred, mixed data if successful. */ @@ -436,8 +437,9 @@ class Utils{ * @see Internet::postURL() * * @param array|string $args + * @param string[] $extraHeaders * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param array[] $headers reference parameter + * @param string[] $headers reference parameter * @param int $httpCode reference parameter * * @return bool|mixed false if an error occurred, mixed data if successful. @@ -456,7 +458,7 @@ class Utils{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param (callable(resource) : void)|null $onSuccess * - * @return array a plain array of three [result body : string, headers : array[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @return array a plain array of three [result body : string, headers : string[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * * @throws \RuntimeException if a cURL error occurs */ From 5cf2fcbbb7f8f5e9c3e80cc7600a9f9459b034e8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Jan 2020 20:38:19 +0000 Subject: [PATCH 2/4] simpleCurl() second return value is string[][], not string[] --- src/pocketmine/utils/Internet.php | 2 +- src/pocketmine/utils/Utils.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 56dd8e3c5..49723d6f7 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -187,7 +187,7 @@ class Internet{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param (callable(resource) : void)|null $onSuccess * - * @return array a plain array of three [result body : string, headers : string[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * * @throws InternetException if a cURL error occurs */ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 46a625341..071a53b10 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -458,7 +458,7 @@ class Utils{ * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. * @phpstan-param (callable(resource) : void)|null $onSuccess * - * @return array a plain array of three [result body : string, headers : string[], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values * * @throws \RuntimeException if a cURL error occurs */ From e007fad5b8e03bc8bfa7234fc55710cfdec92d30 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Jan 2020 20:43:09 +0000 Subject: [PATCH 3/4] fix return types for Utils/Internet getURL()/postURL() --- src/pocketmine/utils/Internet.php | 4 ++-- src/pocketmine/utils/Utils.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 49723d6f7..34118a2ee 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -140,7 +140,7 @@ class Internet{ * @param string[] $headers reference parameter * @param int $httpCode reference parameter * - * @return bool|mixed false if an error occurred, mixed data if successful. + * @return string|false */ public static function getURL(string $page, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ try{ @@ -162,7 +162,7 @@ class Internet{ * @param string[] $headers reference parameter * @param int $httpCode reference parameter * - * @return bool|mixed false if an error occurred, mixed data if successful. + * @return string|false */ public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ try{ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 071a53b10..53b248497 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -426,7 +426,7 @@ class Utils{ * @param string[] $headers reference parameter * @param int $httpCode reference parameter * - * @return bool|mixed false if an error occurred, mixed data if successful. + * @return string|false */ public static function getURL(string $page, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ return Internet::getURL($page, $timeout, $extraHeaders, $err, $headers, $httpCode); @@ -442,7 +442,7 @@ class Utils{ * @param string[] $headers reference parameter * @param int $httpCode reference parameter * - * @return bool|mixed false if an error occurred, mixed data if successful. + * @return string|false */ public static function postURL(string $page, $args, int $timeout = 10, array $extraHeaders = [], &$err = null, &$headers = null, &$httpCode = null){ return Internet::postURL($page, $args, $timeout, $extraHeaders, $err, $headers, $httpCode); From 9cdea437947ed233feab875b2a6d30a68b8648fe Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 29 Jan 2020 20:45:03 +0000 Subject: [PATCH 4/4] provide more array type information for Internet functions --- src/pocketmine/utils/Internet.php | 18 +++++++++++++----- src/pocketmine/utils/Utils.php | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/pocketmine/utils/Internet.php b/src/pocketmine/utils/Internet.php index 34118a2ee..9b85f0eff 100644 --- a/src/pocketmine/utils/Internet.php +++ b/src/pocketmine/utils/Internet.php @@ -139,6 +139,8 @@ class Internet{ * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. * @param string[] $headers reference parameter * @param int $httpCode reference parameter + * @phpstan-param list $extraHeaders + * @phpstan-param array $headers * * @return string|false */ @@ -156,11 +158,14 @@ class Internet{ * POSTs data to an URL * NOTE: This is a blocking operation and can take a significant amount of time. It is inadvisable to use this method on the main thread. * - * @param array|string $args - * @param string[] $extraHeaders - * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param string[] $headers reference parameter - * @param int $httpCode reference parameter + * @param string[]|string $args + * @param string[] $extraHeaders + * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. + * @param string[] $headers reference parameter + * @param int $httpCode reference parameter + * @phpstan-param string|array $args + * @phpstan-param list $extraHeaders + * @phpstan-param array $headers * * @return string|false */ @@ -185,9 +190,12 @@ class Internet{ * @param string[] $extraHeaders extra headers to send as a plain string array * @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. + * @phpstan-param array $extraOpts + * @phpstan-param list $extraHeaders * @phpstan-param (callable(resource) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @phpstan-return array{string, list>, int} * * @throws InternetException if a cURL error occurs */ diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index 53b248497..6688beeda 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -425,6 +425,8 @@ class Utils{ * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. * @param string[] $headers reference parameter * @param int $httpCode reference parameter + * @phpstan-param list $extraHeaders + * @phpstan-param array $headers * * @return string|false */ @@ -436,11 +438,14 @@ class Utils{ * @deprecated * @see Internet::postURL() * - * @param array|string $args - * @param string[] $extraHeaders - * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. - * @param string[] $headers reference parameter - * @param int $httpCode reference parameter + * @param string[]|string $args + * @param string[] $extraHeaders + * @param string $err reference parameter, will be set to the output of curl_error(). Use this to retrieve errors that occured during the operation. + * @param string[] $headers reference parameter + * @param int $httpCode reference parameter + * @phpstan-param string|array $args + * @phpstan-param list $extraHeaders + * @phpstan-param array $headers * * @return string|false */ @@ -456,9 +461,12 @@ class Utils{ * @param string[] $extraHeaders extra headers to send as a plain string array * @param array $extraOpts extra CURLOPT_* to set as an [opt => value] map * @param callable|null $onSuccess function to be called if there is no error. Accepts a resource argument as the cURL handle. + * @phpstan-param array $extraOpts + * @phpstan-param list $extraHeaders * @phpstan-param (callable(resource) : void)|null $onSuccess * * @return array a plain array of three [result body : string, headers : string[][], HTTP response code : int]. Headers are grouped by requests with strtolower(header name) as keys and header value as values + * @phpstan-return array{string, list>, int} * * @throws \RuntimeException if a cURL error occurs */