Skip to content

Commit de54bdb

Browse files
committed
fix: handle ambiguous IResponse.getBody return types
Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent 3d0fb7e commit de54bdb

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

build/psalm-baseline.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,12 +3943,6 @@
39433943
<code><![CDATA[ArrayCache]]></code>
39443944
<code><![CDATA[ArrayCache]]></code>
39453945
</InvalidClass>
3946-
<InvalidReturnStatement>
3947-
<code><![CDATA[$response->getBody()]]></code>
3948-
</InvalidReturnStatement>
3949-
<InvalidReturnType>
3950-
<code><![CDATA[fopen]]></code>
3951-
</InvalidReturnType>
39523946
</file>
39533947
<file src="lib/private/Files/Storage/Local.php">
39543948
<TypeDoesNotContainNull>
@@ -4197,12 +4191,6 @@
41974191
</ImplementedReturnTypeMismatch>
41984192
</file>
41994193
<file src="lib/private/Remote/Instance.php">
4200-
<InvalidReturnStatement>
4201-
<code><![CDATA[$request->getBody()]]></code>
4202-
</InvalidReturnStatement>
4203-
<InvalidReturnType>
4204-
<code><![CDATA[bool|string]]></code>
4205-
</InvalidReturnType>
42064194
<InvalidScalarArgument>
42074195
<code><![CDATA[$response]]></code>
42084196
</InvalidScalarArgument>

lib/private/Files/Storage/DAV.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,13 @@ public function fopen(string $path, string $mode) {
350350
}
351351
}
352352

353-
return $response->getBody();
353+
$content = $response->getBody();
354+
355+
if ($content === null || is_string($content)) {
356+
return false;
357+
}
358+
359+
return $content;
354360
case 'w':
355361
case 'wb':
356362
case 'a':
@@ -390,6 +396,8 @@ public function fopen(string $path, string $mode) {
390396
$this->writeBack($tmpFile, $path);
391397
});
392398
}
399+
400+
return false;
393401
}
394402

395403
public function writeBack(string $tmpFile, string $path): void {

lib/private/Remote/Instance.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ private function getStatus() {
123123
private function downloadStatus($url) {
124124
try {
125125
$request = $this->clientService->newClient()->get($url);
126-
return $request->getBody();
126+
$content = $request->getBody();
127+
128+
// IResponse.getBody responds with null|resource if returning a stream response was requested.
129+
// As that's not the case here, we can just ignore the psalm warning by adding an assertion.
130+
assert(is_string($content));
131+
132+
return $content;
127133
} catch (\Exception $e) {
128134
return false;
129135
}

lib/private/Updater/VersionCheck.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,20 @@ public function check() {
105105
}
106106

107107
/**
108-
* @codeCoverageIgnore
109-
* @param string $url
110-
* @return resource|string
111108
* @throws \Exception
112109
*/
113-
protected function getUrlContent($url) {
114-
$client = $this->clientService->newClient();
115-
$response = $client->get($url, [
110+
protected function getUrlContent(string $url): string {
111+
$response = $this->clientService->newClient()->get($url, [
116112
'timeout' => 5,
117113
]);
118-
return $response->getBody();
114+
115+
$content = $response->getBody();
116+
117+
// IResponse.getBody responds with null|resource if returning a stream response was requested.
118+
// As that's not the case here, we can just ignore the psalm warning by adding an assertion.
119+
assert(is_string($content));
120+
121+
return $content;
119122
}
120123

121124
private function computeCategory(): int {

0 commit comments

Comments
 (0)