Skip to content

Commit

Permalink
Move JSONRPC_VERSION constant into RpcMessageInterface
Browse files Browse the repository at this point in the history
Request::getParam() returns null if the parameter $name does not exist
  • Loading branch information
lucasnetau committed Sep 21, 2021
1 parent 7fab0c1 commit 663877e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* @package EdgeTelemetrics\JSON_RPC
*/
class Notification implements RpcMessageInterface {

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

/**
* @var string A String containing the name of the method to be invoked
*/
Expand Down Expand Up @@ -73,7 +69,7 @@ public function setParam(string $name, $value)
* Get all parameters
* @return array
*/
public function getParams()
public function getParams() : array
{
return $this->params;
}
Expand All @@ -85,7 +81,7 @@ public function getParams()
*/
public function getParam(string $name)
{
return $this->params[$name];
return $this->params[$name] ?? null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function isError(): bool
*/
public function jsonSerialize() : array
{
$record = ['jsonrpc' => Notification::JSONRPC_VERSION];
$record = ['jsonrpc' => self::JSONRPC_VERSION];
$record['id'] = $this->id;
if ($this->isError()) {
$record['error'] = $this->result;
Expand Down
5 changes: 4 additions & 1 deletion src/RpcMessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
/**
* Interface for typehinting in functions that we want a JsonRpc object (request,notification,response)
*/
interface RpcMessageInterface extends JsonSerializable {}
interface RpcMessageInterface extends JsonSerializable {
/** @var string JSONRPC Version String */
const JSONRPC_VERSION = '2.0';
}

0 comments on commit 663877e

Please sign in to comment.