Skip to content

Commit b0f4448

Browse files
authoredFeb 11, 2024··
Merge pull request #151 from Sysix/shepherd
improve psalm level to 1
2 parents 4c10596 + 69faed3 commit b0f4448

8 files changed

+29
-20
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-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sysix\LexOffice\Clients\Traits;
66

77
use Psr\Http\Message\ResponseInterface;
8-
use stdClass;
98
use Sysix\LexOffice\Clients\File;
109
use Sysix\LexOffice\Utils;
1110

@@ -25,10 +24,9 @@ public function document(string $id, bool $asContent = false, string $acceptHead
2524
return $response;
2625
}
2726

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

31-
if ($content === null) {
29+
if ($content === null || !is_object($content) || !property_exists($content, 'documentFileId') || !is_string($content->documentFileId)) {
3230
return $response;
3331
}
3432

‎src/PaginationClient.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Sysix\LexOffice;
66

77
use Psr\Http\Message\ResponseInterface;
8-
use stdClass;
98

109
abstract class PaginationClient extends BaseClient
1110
{
@@ -52,10 +51,13 @@ public function getAll(): ResponseInterface
5251
trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED);
5352

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

58-
if ($result === null || $result->totalPages == 1) {
56+
if (
57+
$result === null || !is_object($result) ||
58+
!property_exists($result, 'totalPages') || $result->totalPages == 1 ||
59+
!property_exists($result, 'content')
60+
) {
5961
return $response;
6062
}
6163

@@ -67,19 +69,19 @@ public function getAll(): ResponseInterface
6769
return $responsePage;
6870
}
6971

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

73-
if ($resultPage === null) {
74+
if (
75+
$resultPage === null ||
76+
!is_object($resultPage) ||
77+
!property_exists($resultPage, 'content') ||
78+
!is_array($resultPage->content) ||
79+
!is_array($result->content)
80+
) {
7481
return $responsePage;
7582
}
7683

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

8587
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)
Please sign in to comment.