Skip to content

Commit eb8f0ac

Browse files
committed
fix: add asserts to prevent psalm warning after bump psalm version
Signed-off-by: Vitor Mattos <[email protected]>
1 parent e2c21bd commit eb8f0ac

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.23.1@8471a896ccea3526b26d082f4461eeea467f10a4">
2+
<files psalm-version="6.5.0@38fc8444edf0cebc9205296ee6e30e906ade783b">
33
<file src="src/NextcloudApiContext.php">
44
<ForbiddenCode>
55
<code><![CDATA[`which jq`]]></code>

src/NextcloudApiContext.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,21 @@ private function testAndGetActualValue(array $value, string $json): string {
283283
);
284284
if (!is_string($actual)) {
285285
$actual = json_encode($actual);
286+
Assert::assertIsString($actual);
286287
}
287288
return $actual;
288289
}
290+
$responseAsJsonString = json_encode($realResponseArray);
291+
Assert::assertIsString($responseAsJsonString);
289292
Assert::assertArrayHasKey(
290293
$value['key'],
291294
$realResponseArray,
292-
'Not found: "' . $value['key'] . '" at array: ' . json_encode($realResponseArray)
295+
'Not found: "' . $value['key'] . '" at array: ' . $responseAsJsonString
293296
);
294297
$actual = $realResponseArray[$value['key']];
295298
if (!is_string($actual)) {
296299
$actual = json_encode($actual);
300+
Assert::assertIsString($actual);
297301
}
298302
return $actual;
299303
}
@@ -327,7 +331,9 @@ public function fetchFieldFromPreviousJsonResponse(string $path): void {
327331
$keys = explode('.', $path);
328332
$value = $responseArray;
329333
foreach ($keys as $key) {
330-
Assert::assertArrayHasKey($key, $value, 'Key [' . $key . '] of path [' . $path . '] not found at body: ' . json_encode($responseArray));
334+
$body = json_encode($responseArray);
335+
Assert::assertIsString($body);
336+
Assert::assertArrayHasKey($key, $value, 'Key [' . $key . '] of path [' . $path . '] not found at body: ' . $body);
331337
$value = $value[$key];
332338
}
333339
if (isset($alias)) {
@@ -419,7 +425,9 @@ private function parseTextRcursive(array &$array): array {
419425
$value = $this->parseText($value);
420426
} elseif ($value instanceof \stdClass) {
421427
$value = (array) $value;
422-
$value = json_decode(json_encode($this->parseTextRcursive($value)));
428+
$buffer = json_encode($this->parseTextRcursive($value));
429+
Assert::assertIsString($buffer);
430+
$value = json_decode($buffer);
423431
}
424432
});
425433
return $array;
@@ -433,6 +441,7 @@ protected function parseText(string $text): string {
433441
$replacements[] = $value;
434442
}
435443
$text = preg_replace($patterns, $replacements, $text);
444+
Assert::assertIsString($text);
436445
return $text;
437446
}
438447

0 commit comments

Comments
 (0)