Skip to content

Commit b9a83d2

Browse files
committed
Bump dev deps, fix minor Psalm issues
Signed-off-by: George Steel <[email protected]>
1 parent 601084a commit b9a83d2

6 files changed

+36
-27
lines changed

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
"willdurand/negotiation": "^3.0"
4949
},
5050
"require-dev": {
51-
"laminas/laminas-coding-standard": "~3.0.0",
52-
"laminas/laminas-diactoros": "^3.4",
53-
"phpunit/phpunit": "^10.5.36",
54-
"psalm/plugin-phpunit": "^0.19.0",
55-
"vimeo/psalm": "^6.0.0"
51+
"laminas/laminas-coding-standard": "~3.0.1",
52+
"laminas/laminas-diactoros": "^3.5",
53+
"phpunit/phpunit": "^10.5.45",
54+
"psalm/plugin-phpunit": "^0.19.2",
55+
"vimeo/psalm": "^6.5.0"
5656
},
5757
"autoload": {
5858
"psr-4": {

composer.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ProblemDetailsResponseFactory.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use function is_callable;
2424
use function is_int;
2525
use function is_resource;
26+
use function is_string;
2627
use function json_decode;
2728
use function json_encode;
2829
use function preg_replace;
@@ -34,6 +35,7 @@
3435
use const JSON_PARTIAL_OUTPUT_ON_ERROR;
3536
use const JSON_PRESERVE_ZERO_FRACTION;
3637
use const JSON_PRETTY_PRINT;
38+
use const JSON_THROW_ON_ERROR;
3739
use const JSON_UNESCAPED_SLASHES;
3840
use const JSON_UNESCAPED_UNICODE;
3941

@@ -308,10 +310,13 @@ protected function getThrowableCode(Throwable $e): int
308310
/** @param ProblemDetails $payload */
309311
protected function generateJsonResponse(array $payload): ResponseInterface
310312
{
313+
$encoded = json_encode($payload, $this->jsonFlags);
314+
assert(is_string($encoded));
315+
311316
return $this->generateResponse(
312317
$payload['status'],
313318
self::CONTENT_TYPE_JSON,
314-
json_encode($payload, $this->jsonFlags),
319+
$encoded,
315320
);
316321
}
317322

@@ -335,11 +340,14 @@ private function cleanKeysForXml(array $input): array
335340
$characterPattern = $startCharacterPattern . '|\-|\.|[0-9]|\xB7|[\x{300}-\x{36F}]|[\x{203F}-\x{2040}]';
336341

337342
$key = preg_replace('/(?!' . $characterPattern . ')./u', '_', $key);
343+
assert(is_string($key));
338344
$key = preg_replace('/^(?!' . $startCharacterPattern . ')./u', '_', $key);
345+
assert(is_string($key));
339346

340347
if (is_array($value)) {
341348
$value = $this->cleanKeysForXml($value);
342349
}
350+
343351
/** @psalm-var mixed */
344352
$return[$key] = $value;
345353
}
@@ -350,8 +358,8 @@ private function cleanKeysForXml(array $input): array
350358
protected function generateXmlResponse(array $payload): ResponseInterface
351359
{
352360
// Ensure any objects are flattened to arrays first
353-
/** @psalm-var array $content */
354-
$content = json_decode(json_encode($payload), true);
361+
$content = json_decode(json_encode($payload, JSON_THROW_ON_ERROR), true, JSON_THROW_ON_ERROR);
362+
assert(is_array($content));
355363

356364
// ensure all keys are valid XML can be json_encoded
357365
$cleanedContent = $this->cleanKeysForXml($content);

test/Exception/ProblemDetailsExceptionInterfaceTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use function json_decode;
1313
use function json_encode;
1414

15+
use const JSON_THROW_ON_ERROR;
16+
1517
final class ProblemDetailsExceptionInterfaceTest extends TestCase
1618
{
1719
private int $status = 403;
@@ -69,7 +71,7 @@ public function testCanCastDetailsToArray(): void
6971

7072
public function testIsJsonSerializable(): void
7173
{
72-
$problem = json_decode(json_encode($this->exception), true);
74+
$problem = json_decode(json_encode($this->exception, JSON_THROW_ON_ERROR), true, JSON_THROW_ON_ERROR);
7375
self::assertIsArray($problem);
7476

7577
self::assertEquals([

test/ProblemDetailsAssertionsTrait.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use function json_encode;
1616
use function simplexml_load_string;
1717

18+
use const JSON_THROW_ON_ERROR;
19+
1820
trait ProblemDetailsAssertionsTrait
1921
{
2022
/**
@@ -73,8 +75,8 @@ public function preparePayloadForXmlResponse(MockObject $stream, callable $asser
7375
public function deserializeXmlPayload(string $xml): array
7476
{
7577
$xml = simplexml_load_string($xml);
76-
$json = json_encode($xml);
77-
$payload = json_decode($json, true);
78+
$json = json_encode($xml, JSON_THROW_ON_ERROR);
79+
$payload = json_decode($json, true, JSON_THROW_ON_ERROR);
7880
assert(is_array($payload));
7981

8082
// Ensure ints and floats are properly represented

test/ProblemDetailsResponseFactoryTest.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ class ProblemDetailsResponseFactoryTest extends TestCase
2828
{
2929
use ProblemDetailsAssertionsTrait;
3030

31-
/** @var ServerRequestInterface&MockObject */
32-
private ServerRequestInterface $request;
33-
34-
/** @var ResponseInterface&MockObject */
35-
private ResponseInterface $response;
36-
31+
private ServerRequestInterface&MockObject $request;
32+
private ResponseInterface&MockObject $response;
3733
private ProblemDetailsResponseFactory $factory;
3834

3935
private const UTF_8_INVALID_2_OCTET_SEQUENCE = "\xc3\x28";
@@ -256,7 +252,8 @@ public function testCreateResponseRemovesResourcesFromInputData(string $header,
256252
$this->response->method('withStatus')->with(500)->willReturn($this->response);
257253
$this->response->method('withHeader')->with('Content-Type', $expectedType)->willReturn($this->response);
258254

259-
$fh = fopen(__FILE__, 'r');
255+
$fh = fopen(__FILE__, 'r');
256+
self::assertNotFalse($fh);
260257
$response = $this->factory->createResponse(
261258
$this->request,
262259
500,

0 commit comments

Comments
 (0)