14
14
15
15
namespace Graze \GuzzleHttp \JsonRpc ;
16
16
17
- use Graze \GuzzleHttp \JsonRpc ;
18
17
use Graze \GuzzleHttp \JsonRpc \Message \MessageFactory ;
19
18
use Graze \GuzzleHttp \JsonRpc \Message \MessageFactoryInterface ;
20
19
use Graze \GuzzleHttp \JsonRpc \Message \RequestInterface ;
@@ -32,12 +31,12 @@ class Client implements ClientInterface
32
31
/**
33
32
* @var HttpClientInterface
34
33
*/
35
- protected $ httpClient ;
34
+ protected HttpClientInterface $ httpClient ;
36
35
37
36
/**
38
37
* @var MessageFactoryInterface
39
38
*/
40
- protected $ messageFactory ;
39
+ protected MessageFactoryInterface $ messageFactory ;
41
40
42
41
/**
43
42
* @param HttpClientInterface $httpClient
@@ -56,12 +55,12 @@ public function __construct(HttpClientInterface $httpClient, MessageFactoryInter
56
55
}
57
56
58
57
/**
59
- * @param string $uri
58
+ * @param string $uri
60
59
* @param array $config
61
60
*
62
61
* @return Client
63
62
*/
64
- public static function factory ($ uri , array $ config = [])
63
+ public static function factory (string $ uri , array $ config = []): Client
65
64
{
66
65
if (isset ($ config ['message_factory ' ])) {
67
66
$ factory = $ config ['message_factory ' ];
@@ -80,12 +79,12 @@ public static function factory($uri, array $config = [])
80
79
*
81
80
* @link http://www.jsonrpc.org/specification#notification
82
81
*
83
- * @param string $method
82
+ * @param string $method
84
83
* @param array|null $params
85
84
*
86
85
* @return RequestInterface
87
86
*/
88
- public function notification ($ method , array $ params = null )
87
+ public function notification (string $ method , array $ params = null ): RequestInterface
89
88
{
90
89
return $ this ->createRequest (RequestInterface::NOTIFICATION , array_filter ([
91
90
'jsonrpc ' => self ::SPEC ,
@@ -100,12 +99,12 @@ public function notification($method, array $params = null)
100
99
* @link http://www.jsonrpc.org/specification#request_object
101
100
*
102
101
* @param mixed $id
103
- * @param string $method
102
+ * @param string $method
104
103
* @param array|null $params
105
104
*
106
105
* @return RequestInterface
107
106
*/
108
- public function request ($ id , $ method , array $ params = null )
107
+ public function request ($ id , string $ method , array $ params = null ): RequestInterface
109
108
{
110
109
return $ this ->createRequest (RequestInterface::REQUEST , array_filter ([
111
110
'jsonrpc ' => self ::SPEC ,
@@ -122,7 +121,7 @@ public function request($id, $method, array $params = null)
122
121
*
123
122
* @return ResponseInterface|null
124
123
*/
125
- public function send (RequestInterface $ request )
124
+ public function send (RequestInterface $ request ): ? ResponseInterface
126
125
{
127
126
$ promise = $ this ->sendAsync ($ request );
128
127
@@ -136,7 +135,7 @@ public function send(RequestInterface $request)
136
135
*
137
136
* @return PromiseInterface
138
137
*/
139
- public function sendAsync (RequestInterface $ request )
138
+ public function sendAsync (RequestInterface $ request ): PromiseInterface
140
139
{
141
140
return $ this ->httpClient ->sendAsync ($ request )->then (
142
141
function (ResponseInterface $ response ) use ($ request ) {
@@ -154,7 +153,7 @@ function (ResponseInterface $response) use ($request) {
154
153
*
155
154
* @return ResponseInterface[]
156
155
*/
157
- public function sendAll (array $ requests )
156
+ public function sendAll (array $ requests ): array
158
157
{
159
158
$ promise = $ this ->sendAllAsync ($ requests );
160
159
@@ -170,7 +169,7 @@ public function sendAll(array $requests)
170
169
*
171
170
* @return PromiseInterface
172
171
*/
173
- public function sendAllAsync (array $ requests )
172
+ public function sendAllAsync (array $ requests ): PromiseInterface
174
173
{
175
174
return $ this ->httpClient ->sendAsync ($ this ->createRequest (
176
175
RequestInterface::BATCH ,
@@ -181,16 +180,16 @@ public function sendAllAsync(array $requests)
181
180
}
182
181
183
182
/**
184
- * @param string $method
183
+ * @param string $method
185
184
* @param array $options
186
185
*
187
186
* @return RequestInterface
188
187
*/
189
- protected function createRequest ($ method , array $ options )
188
+ protected function createRequest (string $ method , array $ options ): RequestInterface
190
189
{
191
190
$ uri = $ this ->httpClient ->getConfig ('base_uri ' );
192
191
$ defaults = $ this ->httpClient ->getConfig ('defaults ' );
193
- $ headers = isset ( $ defaults ['headers ' ]) ? $ defaults [ ' headers ' ] : [];
192
+ $ headers = $ defaults ['headers ' ] ?? [];
194
193
195
194
return $ this ->messageFactory ->createRequest ($ method , $ uri , $ headers , $ options );
196
195
}
@@ -200,10 +199,10 @@ protected function createRequest($method, array $options)
200
199
*
201
200
* @return array
202
201
*/
203
- protected function getBatchRequestOptions (array $ requests )
202
+ protected function getBatchRequestOptions (array $ requests ): array
204
203
{
205
204
return array_map (function (RequestInterface $ request ) {
206
- return JsonRpc \json_decode ((string ) $ request ->getBody ());
205
+ return Json:: decode ((string ) $ request ->getBody ());
207
206
}, $ requests );
208
207
}
209
208
@@ -212,9 +211,9 @@ protected function getBatchRequestOptions(array $requests)
212
211
*
213
212
* @return ResponseInterface[]
214
213
*/
215
- protected function getBatchResponses (ResponseInterface $ response )
214
+ protected function getBatchResponses (ResponseInterface $ response ): array
216
215
{
217
- $ results = JsonRpc \json_decode ((string ) $ response ->getBody (), true );
216
+ $ results = Json:: decode ((string ) $ response ->getBody (), true );
218
217
219
218
return array_map (function (array $ result ) use ($ response ) {
220
219
return $ this ->messageFactory ->createResponse (
0 commit comments