From 2acfdecb8d01d45827e47c29c2bf4fccee33a282 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Thu, 18 Jan 2024 11:44:27 +0100 Subject: [PATCH] RestApiClient: Remove curl's return type hint and wrong curl_error() param Php >= 8 returns CurlHandle instead of resource, which confuses phpstan. --- library/Director/Core/RestApiClient.php | 14 ++++++-------- library/Director/RestApi/RestApiClient.php | 7 +++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/library/Director/Core/RestApiClient.php b/library/Director/Core/RestApiClient.php index b0854ff4..19f6b68b 100644 --- a/library/Director/Core/RestApiClient.php +++ b/library/Director/Core/RestApiClient.php @@ -206,14 +206,14 @@ class RestApiClient } /** - * @return resource + * @throws RuntimeException */ protected function curl() { if ($this->curl === null) { $this->curl = curl_init(sprintf('https://%s:%d', $this->peer, $this->port)); if (! $this->curl) { - throw new RuntimeException('CURL INIT ERROR: ' . curl_error($this->curl)); + throw new RuntimeException('CURL INIT FAILED'); } } @@ -260,13 +260,11 @@ class RestApiClient public function disconnect() { - if ($this->curl !== null) { - if (is_resource($this->curl)) { - @curl_close($this->curl); - } - - $this->curl = null; + if ($this->curl) { + @curl_close($this->curl); } + + $this->curl = null; } public function __destruct() diff --git a/library/Director/RestApi/RestApiClient.php b/library/Director/RestApi/RestApiClient.php index 562e393a..6dcf93c9 100644 --- a/library/Director/RestApi/RestApiClient.php +++ b/library/Director/RestApi/RestApiClient.php @@ -8,7 +8,6 @@ use RuntimeException; class RestApiClient { - /** @var resource */ private $curl; /** @var string HTTP or HTTPS */ @@ -295,14 +294,14 @@ class RestApiClient } /** - * @return resource + * @throws RuntimeException */ protected function curl() { if ($this->curl === null) { - $this->curl = \curl_init(\sprintf('https://%s:%d', $this->host, $this->port)); + $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); if (! $this->curl) { - throw new RuntimeException('CURL INIT ERROR: ' . \curl_error($this->curl)); + throw new RuntimeException('CURL INIT FAILED'); } }