Skip to content

Commit 5669342

Browse files
committed
Add $result to createFromRequest()
1 parent fb29274 commit 5669342

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Response.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class Response implements JsonSerializable {
2525

2626
/**
2727
* Response constructor.
28-
* @param $id
29-
* @param null $result
28+
* @param string|int|float|null $id
29+
* @param mixed|null $result
3030
*/
3131
public function __construct($id, $result = null)
3232
{
@@ -45,16 +45,17 @@ public function __construct($id, $result = null)
4545
/**
4646
* Create a JSONRPC response from a request object
4747
* @param Request $request
48+
* @param mixed|null $result
4849
* @return Response
4950
*/
50-
static public function createFromRequest(Request $request)
51+
static public function createFromRequest(Request $request, $result = null): Response
5152
{
52-
return new self($request->getId());
53+
return new self($request->getId(), $result);
5354
}
5455

5556
/**
5657
* Set the id for the request. This is used between the Client and Server to correlate requests with responses.
57-
* @param string|float|null $id
58+
* @param string|int|float|null $id
5859
*/
5960
public function setId($id)
6061
{
@@ -97,7 +98,7 @@ public function getResult()
9798
/**
9899
* @return bool
99100
*/
100-
public function isSuccess()
101+
public function isSuccess(): bool
101102
{
102103
return (!$this->isError());
103104
}
@@ -123,15 +124,15 @@ public function getError() : Error
123124
/**
124125
* @return bool
125126
*/
126-
public function isError()
127+
public function isError(): bool
127128
{
128129
return ($this->result instanceof Error);
129130
}
130131

131132
/**
132-
* @return mixed
133+
* @return array
133134
*/
134-
public function jsonSerialize()
135+
public function jsonSerialize() : array
135136
{
136137
$record = ['jsonrpc' => Notification::JSONRPC_VERSION];
137138
$record['id'] = $this->id;

0 commit comments

Comments
 (0)