Skip to content

Commit b550622

Browse files
committed
Improve typing
1 parent 1805e12 commit b550622

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/Message.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function isRequest(): bool{
1818
return property_exists($this->value,'method') || property_exists($this->value,'params');
1919
}
2020

21-
public function isNotification($strictId=true): bool{
21+
public function isNotification(bool $strictId=true): bool{
2222
return $this->isRequest() && (!property_exists($this->value,'id') || !($strictId?($this->value->id!==null):($this->value->id)));
2323
}
2424

@@ -48,7 +48,6 @@ public static function createRequestMessageV1($id,string $method,array $params=[
4848
}
4949

5050
/**
51-
* @param $id
5251
* @param string $method
5352
* @param array $params
5453
* @return NotificationMessage
@@ -117,7 +116,7 @@ public static function decodeJSON(string $json){
117116
}
118117

119118
/**
120-
* @param $object
119+
* @param mixed $object
121120
* @param bool $strictId
122121
* @return Message
123122
* @throws JSONRPCException
@@ -130,12 +129,12 @@ public static function parseObject($object,bool $strictId=true){
130129
}
131130

132131
/**
133-
* @param $message
132+
* @param object $message
134133
* @param bool $strictId
135134
* @return Message
136135
* @throws JSONRPCException
137136
*/
138-
private static function handleMessage($message,bool $strictId=true){
137+
private static function handleMessage(object $message,bool $strictId=true){
139138
if(property_exists($message,'jsonrpc')){
140139
if($message->jsonrpc==='2.0'){
141140
return self::handleMessageV2($message,$strictId);
@@ -147,13 +146,14 @@ private static function handleMessage($message,bool $strictId=true){
147146
}
148147

149148
/**
150-
* @param $message
149+
* @param object $message
151150
* @param bool $strictId
152151
* @return null
153152
* @throws JSONRPCException
154153
*/
155-
private static function handleMessageV2($message,bool $strictId=true){
154+
private static function handleMessageV2(object $message,bool $strictId=true){
156155
if(self::isRequestMessage($message)){
156+
self::validateMethodPropertyV1($message);
157157
return null;
158158
}elseif(self::isResponseMessage($message)){
159159
return null;
@@ -163,11 +163,19 @@ private static function handleMessageV2($message,bool $strictId=true){
163163
}
164164

165165

166-
private static function isRequestMessage($message): bool{
166+
/**
167+
* @param object $message
168+
* @return bool
169+
*/
170+
private static function isRequestMessage(object $message): bool{
167171
return property_exists($message,'method') || property_exists($message,'params');
168172
}
169173

170-
private static function isResponseMessage($message): bool{
174+
/**
175+
* @param object $message
176+
* @return bool
177+
*/
178+
private static function isResponseMessage(object $message): bool{
171179
return property_exists($message,'result') || property_exists($message,'error');
172180
}
173181

@@ -186,11 +194,11 @@ private static function validateMethodPropertyV1(object $message){
186194
}
187195

188196
/**
189-
* @param $message
197+
* @param object $message
190198
* @return void
191199
* @throws JSONRPCException
192200
*/
193-
private static function validateParamsPropertyV1($message){
201+
private static function validateParamsPropertyV1(object $message){
194202
if(!property_exists($message,'params')){
195203
throw new JSONRPCException('[V1] Missing "params" property in request.');
196204
}
@@ -200,22 +208,22 @@ private static function validateParamsPropertyV1($message){
200208
}
201209

202210
/**
203-
* @param $message
211+
* @param object $message
204212
* @return void
205213
* @throws JSONRPCException
206214
*/
207-
private static function validateResultPropertyV1($message){
215+
private static function validateResultPropertyV1(object $message){
208216
if(!property_exists($message,'result')){
209217
throw new JSONRPCException('[V1] Missing "result" property in request.');
210218
}
211219
}
212220

213221
/**
214-
* @param $message
222+
* @param object $message
215223
* @return void
216224
* @throws JSONRPCException
217225
*/
218-
private static function validateErrorPropertyV1($message){
226+
private static function validateErrorPropertyV1(object $message){
219227
if(!property_exists($message,'error')){
220228
throw new JSONRPCException('[V1] Missing "error" property in request.');
221229
}
@@ -225,12 +233,12 @@ private static function validateErrorPropertyV1($message){
225233
}
226234

227235
/**
228-
* @param $message
236+
* @param object $message
229237
* @param bool $strictId
230238
* @return Message
231239
* @throws JSONRPCException
232240
*/
233-
private static function handleMessageV1($message,bool $strictId=true){
241+
private static function handleMessageV1(object $message,bool $strictId=true){
234242
if(self::isRequestMessage($message)){
235243
self::validateMethodPropertyV1($message);
236244
self::validateParamsPropertyV1($message);

0 commit comments

Comments
 (0)