Skip to content

Commit 1df831b

Browse files
committed
improve psalm level to 1
1 parent aaddb0d commit 1df831b

8 files changed

+29
-18
lines changed

psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="5"
3+
errorLevel="1"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

src/Api.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public function newRequest(string $method, string $resource, array $headers = []
5454

5555
public function setRequest(RequestInterface $request): self
5656
{
57-
$request = $request->withHeader('Authorization', 'Bearer ' . $this->apiKey);
57+
if (!$request->hasHeader('Authorization')) {
58+
$request = $request->withHeader('Authorization', 'Bearer ' . $this->apiKey);
59+
}
5860

5961
if (!$request->hasHeader('Accept')) {
6062
$request = $request->withHeader('Accept', 'application/json');

src/Clients/Traits/DocumentClientTrait.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ public function document(string $id, bool $asContent = false, string $acceptHead
2525
return $response;
2626
}
2727

28-
/** @var ?stdClass{documentField: string} $content */
2928
$content = Utils::getJsonFromResponse($response);
3029

31-
if ($content === null) {
30+
if ($content === null || !is_object($content) || !property_exists($content, 'documentFileId') || !is_string($content->documentFileId)) {
3231
return $response;
3332
}
3433

src/PaginationClient.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ public function getAll(): ResponseInterface
5252
trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED);
5353

5454
$response = $this->getPage(0);
55-
/** @var ?stdClass{totalPages:int, content:stdClass[]} $result */
5655
$result = Utils::getJsonFromResponse($response);
5756

58-
if ($result === null || $result->totalPages == 1) {
57+
if (
58+
$result === null || !is_object($result) ||
59+
!property_exists($result, 'totalPages') || $result->totalPages == 1 ||
60+
!property_exists($result, 'content')
61+
) {
5962
return $response;
6063
}
6164

@@ -67,19 +70,19 @@ public function getAll(): ResponseInterface
6770
return $responsePage;
6871
}
6972

70-
/** @var ?stdClass{totalPages:int, content:stdClass[]} $resultPage */
7173
$resultPage = Utils::getJsonFromResponse($responsePage);
7274

73-
if ($resultPage === null) {
75+
if (
76+
$resultPage === null ||
77+
!is_object($resultPage) ||
78+
!property_exists($resultPage, 'content') ||
79+
!is_array($resultPage->content) ||
80+
!is_array($result->content)
81+
) {
7482
return $responsePage;
7583
}
7684

77-
foreach ($resultPage->content as $entity) {
78-
$result->content = [
79-
...$result->content,
80-
$entity
81-
];
82-
}
85+
array_push($result->content, ...$resultPage->content);
8386
}
8487

8588
return $response->withBody(Utils::createStream($result));

src/Utils.php

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static function jsonEncode(mixed $value, int $options = 0, int $depth = 5
6161
*/
6262
public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0): mixed
6363
{
64+
/** @var mixed $data */
6465
$data = json_decode($json, $assoc, $depth, $options);
6566
if (JSON_ERROR_NONE !== json_last_error()) {
6667
throw new InvalidArgumentException('json_decode error: ' . json_last_error_msg());

tests/PaginationClientTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class PaginationClientTest extends TestClient
1313
{
1414
/**
15-
* @param Response[] $responses
15+
* @param array<int, Response> $responses
1616
*
1717
* @return array{0: Api&MockObject, 1: PaginationClient}
1818
*/

tests/TestClient.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function createApiMockObject(Response $response)
4141
}
4242

4343
/**
44-
* @param Response[] $responses
44+
* @param array<int, Response> $responses
4545
*
4646
* @return Api&MockObject
4747
*/
@@ -76,8 +76,8 @@ public function createClientMockObject(string $className): array
7676
/**
7777
* @template T of ClientInterface
7878
*
79-
* @param class-string<T> $className
80-
* @param Response[] $responses
79+
* @param class-string<T> $className
80+
* @param array<int, Response> $responses
8181
*
8282
* @return array{0: Api&MockObject, 1: T&MockObject}
8383
*/

tests/UtilsTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function testGetJsonFromResponseWithValidHeader(): void
3636
], (string) json_encode([
3737
'test' => true
3838
]));
39+
40+
/** @var object $json */
3941
$json = Utils::getJsonFromResponse($response);
4042

4143
$this->assertEquals((object)[
@@ -50,6 +52,8 @@ public function testGetJsonFromResponseWithValidCharsetHeader(): void
5052
], (string) json_encode([
5153
'test' => true
5254
]));
55+
56+
/** @var object $json */
5357
$json = Utils::getJsonFromResponse($response);
5458

5559
$this->assertEquals((object)[
@@ -59,6 +63,8 @@ public function testGetJsonFromResponseWithValidCharsetHeader(): void
5963

6064
public function testJsonDecodeValid(): void
6165
{
66+
67+
/** @var object $json */
6268
$json = Utils::jsonDecode('{"content":"test","object":{"content":"test2"}}');
6369

6470
$this->assertEquals($json, (object)[

0 commit comments

Comments
 (0)