Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -4059,16 +4053,6 @@
<code><![CDATA[isAdmin]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/private/Http/Client/Response.php">
<InvalidNullableReturnType>
<code><![CDATA[string|resource]]></code>
</InvalidNullableReturnType>
<NullableReturnStatement>
<code><![CDATA[$this->stream ?
$this->response->getBody()->detach():
$this->response->getBody()->getContents()]]></code>
</NullableReturnStatement>
</file>
<file src="lib/private/Installer.php">
<InvalidArgument>
<code><![CDATA[false]]></code>
Expand Down Expand Up @@ -4207,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>
Expand Down
10 changes: 9 additions & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 3 additions & 30 deletions lib/private/Http/Client/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -64,9 +40,6 @@ public function getHeader(string $key): string {
return $headers[0];
}

/**
* @return array
*/
public function getHeaders(): array {
return $this->response->getHeaders();
}
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Remote/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 10 additions & 7 deletions lib/private/Updater/VersionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Http/Client/IResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading