fix: handle ambiguous IResponse.getBody return types

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/53679/head
Daniel Kesselberg 6 months ago
parent 3d0fb7e603
commit de54bdb06b
No known key found for this signature in database
GPG Key ID: 4A81C29F63464E8F
  1. 12
      build/psalm-baseline.xml
  2. 10
      lib/private/Files/Storage/DAV.php
  3. 8
      lib/private/Remote/Instance.php
  4. 17
      lib/private/Updater/VersionCheck.php

@ -3943,12 +3943,6 @@
<code><![CDATA[ArrayCache]]></code>
<code><![CDATA[ArrayCache]]></code>
</InvalidClass>
<InvalidReturnStatement>
<code><![CDATA[$response->getBody()]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[fopen]]></code>
</InvalidReturnType>
</file>
<file src="lib/private/Files/Storage/Local.php">
<TypeDoesNotContainNull>
@ -4197,12 +4191,6 @@
</ImplementedReturnTypeMismatch>
</file>
<file src="lib/private/Remote/Instance.php">
<InvalidReturnStatement>
<code><![CDATA[$request->getBody()]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[bool|string]]></code>
</InvalidReturnType>
<InvalidScalarArgument>
<code><![CDATA[$response]]></code>
</InvalidScalarArgument>

@ -350,7 +350,13 @@ class DAV extends Common {
}
}
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 @@ class DAV extends Common {
$this->writeBack($tmpFile, $path);
});
}
return false;
}
public function writeBack(string $tmpFile, string $path): void {

@ -123,7 +123,13 @@ class Instance implements IInstance {
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;
}

@ -105,17 +105,20 @@ class VersionCheck {
}
/**
* @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 {

Loading…
Cancel
Save