Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"php": "^8.2",
"ext-json": "*",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"thecodingmachine/safe": "^2"
"psr/http-message": "^1.0 || ^2.0"
},
"require-dev": {
"cdn77/coding-standard": "^7.0",
Expand All @@ -30,8 +29,7 @@
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.0.0",
"phpunit/phpunit": "^11.0",
"psr-mock/http": "^1.0",
"thecodingmachine/phpstan-safe-rule": "^1.0"
"psr-mock/http": "^1.0"
},
"config": {
"allow-plugins": {
Expand Down
6 changes: 4 additions & 2 deletions src/Extractor/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use Psr\Http\Message\MessageInterface;

use function Safe\json_decode;
use function json_decode;

use const JSON_THROW_ON_ERROR;

abstract class Extractor
{
Expand All @@ -16,7 +18,7 @@ abstract class Extractor
public function __construct(MessageInterface $message)
{
/** @var array{id: string, jsonrpc: string, error?: array{code: int, message: string, data?: mixed}, method: string, params?: array<string, mixed>, result?: mixed} $contents */
$contents = json_decode((string) $message->getBody(), true);
$contents = json_decode((string) $message->getBody(), true, flags: JSON_THROW_ON_ERROR);
$this->messageContents = $contents;
}
}
8 changes: 6 additions & 2 deletions src/HttpJsonRpcRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\StreamFactoryInterface;

use function Safe\json_encode;
use function json_encode;

use const JSON_THROW_ON_ERROR;

final class HttpJsonRpcRequestFactory implements JsonRpcRequestFactory
{
Expand Down Expand Up @@ -49,8 +51,10 @@ public function request(string|int|null $id, string $method, array|null $params
/** @param mixed[] $body */
private function createRequest(array $body = []): RequestInterface
{
$encodedBody = json_encode($body, JSON_THROW_ON_ERROR);

return $this->messageFactory->createRequest('POST', '')
->withHeader('Content-Type', 'application/json')
->withBody($this->streamFactory->createStream(json_encode($body)));
->withBody($this->streamFactory->createStream($encodedBody));
}
}
2 changes: 1 addition & 1 deletion tests/HttpJsonRpcRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PsrMock\Psr17\RequestFactory;
use PsrMock\Psr17\StreamFactory;

use function Safe\preg_replace;
use function preg_replace;

#[CoversClass(HttpJsonRpcRequestFactory::class)]
final class HttpJsonRpcRequestFactoryTest extends TestCase
Expand Down
Loading