Skip to content

Commit 663877e

Browse files
committed
Move JSONRPC_VERSION constant into RpcMessageInterface
Request::getParam() returns null if the parameter $name does not exist
1 parent 7fab0c1 commit 663877e

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/Notification.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
* @package EdgeTelemetrics\JSON_RPC
88
*/
99
class Notification implements RpcMessageInterface {
10-
11-
/** @var string JSONRPC Version String */
12-
const JSONRPC_VERSION = '2.0';
13-
1410
/**
1511
* @var string A String containing the name of the method to be invoked
1612
*/
@@ -73,7 +69,7 @@ public function setParam(string $name, $value)
7369
* Get all parameters
7470
* @return array
7571
*/
76-
public function getParams()
72+
public function getParams() : array
7773
{
7874
return $this->params;
7975
}
@@ -85,7 +81,7 @@ public function getParams()
8581
*/
8682
public function getParam(string $name)
8783
{
88-
return $this->params[$name];
84+
return $this->params[$name] ?? null;
8985
}
9086

9187
/**

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function isError(): bool
133133
*/
134134
public function jsonSerialize() : array
135135
{
136-
$record = ['jsonrpc' => Notification::JSONRPC_VERSION];
136+
$record = ['jsonrpc' => self::JSONRPC_VERSION];
137137
$record['id'] = $this->id;
138138
if ($this->isError()) {
139139
$record['error'] = $this->result;

src/RpcMessageInterface.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
/**
88
* Interface for typehinting in functions that we want a JsonRpc object (request,notification,response)
99
*/
10-
interface RpcMessageInterface extends JsonSerializable {}
10+
interface RpcMessageInterface extends JsonSerializable {
11+
/** @var string JSONRPC Version String */
12+
const JSONRPC_VERSION = '2.0';
13+
}

0 commit comments

Comments
 (0)