Skip to content

Commit c240ee6

Browse files
committed
Add interface RpcMessageInterface to allow for type hinting of a JSON-RPC object (request,notification,response) in usage of the library
1 parent 5669342 commit c240ee6

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/Notification.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22

33
namespace EdgeTelemetrics\JSON_RPC;
44

5-
use JsonSerializable;
6-
75
/**
86
* Class Notification
97
* @package EdgeTelemetrics\JSON_RPC
108
*/
11-
class Notification implements JsonSerializable {
9+
class Notification implements RpcMessageInterface {
1210

1311
/** @var string JSONRPC Version String */
1412
const JSONRPC_VERSION = '2.0';
1513

1614
/**
1715
* @var string A String containing the name of the method to be invoked
1816
*/
19-
protected $method = '';
17+
protected string $method = '';
2018

2119
/**
2220
* @var array A Structured value that holds the parameter values to be used during the invocation of the method
2321
*/
24-
protected $params = [];
22+
protected array $params = [];
2523

2624
/**
2725
* Notification constructor.

src/Request.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace EdgeTelemetrics\JSON_RPC;
44

5-
use JsonSerializable;
65
use RuntimeException;
76

87
use function is_float;
@@ -16,7 +15,7 @@
1615
*
1716
* Request extends Notification and includes the Id property
1817
*/
19-
class Request extends Notification implements JsonSerializable {
18+
class Request extends Notification implements RpcMessageInterface {
2019

2120
/**
2221
* @var string|int|null An identifier established by the Client that MUST contain a String, Number, or NULL value

src/Response.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace EdgeTelemetrics\JSON_RPC;
44

5-
use JsonSerializable;
65
use RuntimeException;
76

87
use function is_float;
@@ -14,7 +13,7 @@
1413
* Class Response
1514
* @package EdgeTelemetrics\JSON_RPC
1615
*/
17-
class Response implements JsonSerializable {
16+
class Response implements RpcMessageInterface {
1817
/**
1918
* @var string|int|null
2019
*/

src/RpcMessageInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace EdgeTelemetrics\JSON_RPC;
4+
5+
use JsonSerializable;
6+
7+
/**
8+
* Interface for typehinting in functions that we want a JsonRpc object (request,notification,response)
9+
*/
10+
interface RpcMessageInterface extends JsonSerializable {}

0 commit comments

Comments
 (0)