diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 26ee47735ad17..e40c10bfc6727 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -3943,12 +3943,6 @@ - - getBody()]]> - - - - @@ -4059,16 +4053,6 @@ - - - - - - stream ? - $this->response->getBody()->detach(): - $this->response->getBody()->getContents()]]> - - @@ -4207,12 +4191,6 @@ - - getBody()]]> - - - - diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 10670d6331a0e..afd8f87e2de4b 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -350,7 +350,13 @@ public function fopen(string $path, string $mode) { } } - return $response->getBody(); + $content = $response->getBody(); + + if ($content === null || is_string($content)) { + return false; + } + + return $content; case 'w': case 'wb': case 'a': @@ -390,6 +396,8 @@ public function fopen(string $path, string $mode) { $this->writeBack($tmpFile, $path); }); } + + return false; } public function writeBack(string $tmpFile, string $path): void { diff --git a/lib/private/Http/Client/Response.php b/lib/private/Http/Client/Response.php index adf83306d077b..dc0b17ab075c9 100644 --- a/lib/private/Http/Client/Response.php +++ b/lib/private/Http/Client/Response.php @@ -11,49 +11,25 @@ use OCP\Http\Client\IResponse; use Psr\Http\Message\ResponseInterface; -/** - * Class Response - * - * @package OC\Http - */ class Response implements IResponse { - /** @var ResponseInterface */ - private $response; - - /** - * @var bool - */ - private $stream; + private ResponseInterface $response; + private bool $stream; - /** - * @param ResponseInterface $response - * @param bool $stream - */ - public function __construct(ResponseInterface $response, $stream = false) { + public function __construct(ResponseInterface $response, bool $stream = false) { $this->response = $response; $this->stream = $stream; } - /** - * @return string|resource - */ public function getBody() { return $this->stream ? $this->response->getBody()->detach(): $this->response->getBody()->getContents(); } - /** - * @return int - */ public function getStatusCode(): int { return $this->response->getStatusCode(); } - /** - * @param string $key - * @return string - */ public function getHeader(string $key): string { $headers = $this->response->getHeader($key); @@ -64,9 +40,6 @@ public function getHeader(string $key): string { return $headers[0]; } - /** - * @return array - */ public function getHeaders(): array { return $this->response->getHeaders(); } diff --git a/lib/private/Remote/Instance.php b/lib/private/Remote/Instance.php index ac3233b93c93d..b85813ebf7190 100644 --- a/lib/private/Remote/Instance.php +++ b/lib/private/Remote/Instance.php @@ -123,7 +123,13 @@ private function getStatus() { private function downloadStatus($url) { try { $request = $this->clientService->newClient()->get($url); - return $request->getBody(); + $content = $request->getBody(); + + // IResponse.getBody responds with null|resource if returning a stream response was requested. + // As that's not the case here, we can just ignore the psalm warning by adding an assertion. + assert(is_string($content)); + + return $content; } catch (\Exception $e) { return false; } diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php index 53bfc0d5d5f15..be410b06c3e64 100644 --- a/lib/private/Updater/VersionCheck.php +++ b/lib/private/Updater/VersionCheck.php @@ -105,17 +105,20 @@ public function check() { } /** - * @codeCoverageIgnore - * @param string $url - * @return resource|string * @throws \Exception */ - protected function getUrlContent($url) { - $client = $this->clientService->newClient(); - $response = $client->get($url, [ + protected function getUrlContent(string $url): string { + $response = $this->clientService->newClient()->get($url, [ 'timeout' => 5, ]); - return $response->getBody(); + + $content = $response->getBody(); + + // IResponse.getBody responds with null|resource if returning a stream response was requested. + // As that's not the case here, we can just ignore the psalm warning by adding an assertion. + assert(is_string($content)); + + return $content; } private function computeCategory(): int { diff --git a/lib/public/Http/Client/IResponse.php b/lib/public/Http/Client/IResponse.php index deec2cf97b13c..53032ef2a3772 100644 --- a/lib/public/Http/Client/IResponse.php +++ b/lib/public/Http/Client/IResponse.php @@ -15,8 +15,9 @@ */ interface IResponse { /** - * @return string|resource + * @return null|resource|string * @since 8.1.0 + * @sicne 8.2.0 with stream enabled, the function returns null or a resource */ public function getBody();