Skip to content

Commit 8bf1968

Browse files
authored
feat: remove Safe (#92)
1 parent fc32b93 commit 8bf1968

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"php": "^8.2",
2020
"ext-json": "*",
2121
"psr/http-factory": "^1.0",
22-
"psr/http-message": "^1.0 || ^2.0",
23-
"thecodingmachine/safe": "^2"
22+
"psr/http-message": "^1.0 || ^2.0"
2423
},
2524
"require-dev": {
2625
"cdn77/coding-standard": "^7.0",
@@ -30,8 +29,7 @@
3029
"phpstan/phpstan-phpunit": "^1.0.0",
3130
"phpstan/phpstan-strict-rules": "^1.0.0",
3231
"phpunit/phpunit": "^11.0",
33-
"psr-mock/http": "^1.0",
34-
"thecodingmachine/phpstan-safe-rule": "^1.0"
32+
"psr-mock/http": "^1.0"
3533
},
3634
"config": {
3735
"allow-plugins": {

src/Extractor/Extractor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
use Psr\Http\Message\MessageInterface;
88

9-
use function Safe\json_decode;
9+
use function json_decode;
10+
11+
use const JSON_THROW_ON_ERROR;
1012

1113
abstract class Extractor
1214
{
@@ -16,7 +18,7 @@ abstract class Extractor
1618
public function __construct(MessageInterface $message)
1719
{
1820
/** @var array{id: string, jsonrpc: string, error?: array{code: int, message: string, data?: mixed}, method: string, params?: array<string, mixed>, result?: mixed} $contents */
19-
$contents = json_decode((string) $message->getBody(), true);
21+
$contents = json_decode((string) $message->getBody(), true, flags: JSON_THROW_ON_ERROR);
2022
$this->messageContents = $contents;
2123
}
2224
}

src/HttpJsonRpcRequestFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\StreamFactoryInterface;
1010

11-
use function Safe\json_encode;
11+
use function json_encode;
12+
13+
use const JSON_THROW_ON_ERROR;
1214

1315
final class HttpJsonRpcRequestFactory implements JsonRpcRequestFactory
1416
{
@@ -49,8 +51,10 @@ public function request(string|int|null $id, string $method, array|null $params
4951
/** @param mixed[] $body */
5052
private function createRequest(array $body = []): RequestInterface
5153
{
54+
$encodedBody = json_encode($body, JSON_THROW_ON_ERROR);
55+
5256
return $this->messageFactory->createRequest('POST', '')
5357
->withHeader('Content-Type', 'application/json')
54-
->withBody($this->streamFactory->createStream(json_encode($body)));
58+
->withBody($this->streamFactory->createStream($encodedBody));
5559
}
5660
}

tests/HttpJsonRpcRequestFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PsrMock\Psr17\RequestFactory;
1010
use PsrMock\Psr17\StreamFactory;
1111

12-
use function Safe\preg_replace;
12+
use function preg_replace;
1313

1414
#[CoversClass(HttpJsonRpcRequestFactory::class)]
1515
final class HttpJsonRpcRequestFactoryTest extends TestCase

0 commit comments

Comments
 (0)