1212 */
1313trait Request
1414{
15- /**
16- * Instance of Client.
17- */
15+
1816 protected static $ client ;
1917
20- /**
21- * Response from requests made to Paystack.
22- *
23- * @var mixed
24- */
25- protected static $ response ;
2618
27- /**
28- * @param null|array|mixed $params The list of parameters to validate
29- * @param bool $required
30- *
31- * @throws InvalidArgumentException if $params exists and is not an array
32- */
33- public static function validateParams ($ params = null , $ required = false ): void
19+ protected static mixed $ response ;
20+
21+
22+ public static function validateParams (mixed $ params = null , bool $ required = false ): void
3423 {
3524 if ($ required ) {
3625 if (empty ($ params ) || ! is_array ($ params )) {
@@ -46,18 +35,7 @@ public static function validateParams($params = null, $required = false): void
4635 }
4736 }
4837
49- /**
50- * @param string $method HTTP method ('get', 'post', etc.)
51- * @param string $url URL for the request
52- * @param array $params list of parameters for the request
53- * @param string $return_type return array or object accepted values: 'arr' and 'obj'
54- *
55- * @throws InvalidArgumentException
56- * @throws IsNullException
57- *
58- * @return array|object (the JSON response as array or object)
59- */
60- public static function staticRequest ($ method , $ url , $ params = [], $ return_type = 'obj ' )
38+ public static function staticRequest (string $ method , string $ url , array $ params = [], string $ return_type = 'obj ' ): array |object
6139 {
6240 if ($ return_type != 'arr ' && $ return_type != 'obj ' ) {
6341 throw new InvalidArgumentException ('Return type can only be obj or arr ' );
@@ -90,18 +68,9 @@ protected static function setRequestOptions(): void
9068 );
9169 }
9270
93- /**
94- * @param string $url
95- * @param string $method
96- * @param array $body
97- *
98- * @throws IsNullException
99- */
100- private static function setHttpResponse ($ method , $ url , $ body = []): \GuzzleHttp \Psr7 \Response
71+
72+ private static function setHttpResponse (string $ method , string $ url , array $ body = []): \GuzzleHttp \Psr7 \Response
10173 {
102- if (is_null ($ method )) {
103- throw new IsNullException ('Empty method not allowed ' );
104- }
10574
10675 static ::setRequestOptions ();
10776
@@ -113,21 +82,13 @@ private static function setHttpResponse($method, $url, $body = []): \GuzzleHttp\
11382 return static ::$ response ;
11483 }
11584
116- /**
117- * Get the data response from an API operation.
118- *
119- * @return array
120- */
85+
12186 private static function getResponse (): array
12287 {
12388 return json_decode (static ::$ response ->getBody (), true );
12489 }
12590
126- /**
127- * Get the data response from a get operation.
128- *
129- * @return array
130- */
91+
13192 private static function getResponseData (): array
13293 {
13394 return json_decode (static ::$ response ->getBody (), true )['data ' ];
0 commit comments