@@ -65,30 +65,24 @@ class Client implements ClientInterface, LoggerAwareInterface
65
65
/**
66
66
* Logger interface to use for log messages.
67
67
*
68
- * @var LoggerInterface|NullLogger|null
68
+ * @var LoggerInterface|NullLogger
69
69
*/
70
70
public LoggerInterface $ logger ;
71
71
72
72
protected HttpClient $ client ;
73
73
74
74
/**
75
75
* The DNS Made Easy API Key.
76
- *
77
- * @var string
78
76
*/
79
77
protected string $ apiKey ;
80
78
81
79
/**
82
80
* The DNS Made Easy Secret Key.
83
- *
84
- * @var string
85
81
*/
86
82
protected string $ secretKey ;
87
83
88
84
/**
89
85
* The DNS Made Easy API Endpoint.
90
- *
91
- * @var string
92
86
*/
93
87
protected string $ endpoint = 'https://api.dnsmadeeasy.com/V2.0 ' ;
94
88
@@ -102,14 +96,14 @@ class Client implements ClientInterface, LoggerAwareInterface
102
96
/**
103
97
* A cache of instantiated manager classes.
104
98
*
105
- * @var array
99
+ * @var mixed[]
106
100
*/
107
101
protected array $ managers = [];
108
102
109
103
/**
110
104
* A map of manager names to classes.
111
105
*
112
- * @var array| string[]
106
+ * @var string[]
113
107
*/
114
108
protected array $ managerMap = [
115
109
'contactlists ' => ContactListManager::class,
@@ -126,22 +120,16 @@ class Client implements ClientInterface, LoggerAwareInterface
126
120
127
121
/**
128
122
* The ID of the last request to the API.
129
- *
130
- * @var string|null
131
123
*/
132
124
protected ?string $ requestId = null ;
133
125
134
126
/**
135
127
* The request limit on the API.
136
- *
137
- * @var int|null
138
128
*/
139
129
protected ?int $ requestLimit = null ;
140
130
141
131
/**
142
132
* The number of requests remaining until the limit is hit.
143
- *
144
- * @var int|null
145
133
*/
146
134
protected ?int $ requestsRemaining = null ;
147
135
@@ -166,10 +154,10 @@ public function __construct(?HttpClient $client = null, ?PaginatorFactoryInterfa
166
154
$ this ->logger = $ logger ;
167
155
}
168
156
169
- public function __get ($ name )
157
+ public function __get (string $ name ): mixed
170
158
{
171
159
// Usage is a special manager and not like the others.
172
- if ($ name == 'usage ' ) {
160
+ if ($ name === 'usage ' ) {
173
161
if (! isset ($ this ->managers ['usage ' ])) {
174
162
$ this ->managers ['usage ' ] = new UsageManager ($ this );
175
163
}
@@ -179,7 +167,7 @@ public function __get($name)
179
167
return $ this ->getManager ($ name );
180
168
}
181
169
182
- public function setLogger (LoggerInterface $ logger )
170
+ public function setLogger (LoggerInterface $ logger ): void
183
171
{
184
172
$ this ->logger = $ logger ;
185
173
}
@@ -244,10 +232,10 @@ public function getPaginatorFactory(): PaginatorFactoryInterface
244
232
return $ this ->paginatorFactory ;
245
233
}
246
234
247
- public function get (string $ url , array $ params = [] ): ResponseInterface
235
+ public function get (string $ url , ? array $ params = null ): ResponseInterface
248
236
{
249
237
$ queryString = '' ;
250
- if ($ params ) {
238
+ if ($ params !== null ) {
251
239
$ queryString = '? ' . http_build_query ($ params );
252
240
}
253
241
$ url .= $ queryString ;
@@ -256,28 +244,28 @@ public function get(string $url, array $params = []): ResponseInterface
256
244
return $ this ->send ($ request );
257
245
}
258
246
259
- public function post (string $ url , $ payload ): ResponseInterface
247
+ public function post (string $ url , mixed $ payload ): ResponseInterface
260
248
{
261
249
$ request = new Request ('POST ' , $ this ->endpoint . $ url , [], 'php://temp ' );
262
250
$ request ->withHeader ('Content-Type ' , 'application/json ' );
263
- $ request ->getBody ()->write (json_encode ($ payload ));
251
+ $ request ->getBody ()->write (json_encode ($ payload, JSON_THROW_ON_ERROR ));
264
252
return $ this ->send ($ request );
265
253
}
266
254
267
- public function put (string $ url , $ payload ): ResponseInterface
255
+ public function put (string $ url , mixed $ payload ): ResponseInterface
268
256
{
269
257
$ request = new Request ('PUT ' , $ this ->endpoint . $ url , [], 'php://temp ' );
270
258
$ request ->withHeader ('Content-Type ' , 'application/json ' );
271
- $ request ->getBody ()->write (json_encode ($ payload ));
259
+ $ request ->getBody ()->write (json_encode ($ payload, JSON_THROW_ON_ERROR ));
272
260
return $ this ->send ($ request );
273
261
}
274
262
275
- public function delete (string $ url , $ payload = null ): ResponseInterface
263
+ public function delete (string $ url , mixed $ payload = null ): ResponseInterface
276
264
{
277
265
$ request = new Request ('DELETE ' , $ this ->endpoint . $ url );
278
- if ($ payload ) {
266
+ if ($ payload !== null ) {
279
267
$ request ->withHeader ('Content-Type ' , 'application/json ' );
280
- $ request ->getBody ()->write (json_encode ($ payload ));
268
+ $ request ->getBody ()->write (json_encode ($ payload, JSON_THROW_ON_ERROR ));
281
269
}
282
270
return $ this ->send ($ request );
283
271
}
@@ -313,8 +301,6 @@ public function send(RequestInterface $request): ResponseInterface
313
301
314
302
/**
315
303
* Return the ID of the last API request.
316
- *
317
- * @return string|null
318
304
*/
319
305
public function getLastRequestId (): ?string
320
306
{
@@ -323,8 +309,6 @@ public function getLastRequestId(): ?string
323
309
324
310
/**
325
311
* Get the request limit.
326
- *
327
- * @return int|null
328
312
*/
329
313
public function getRequestLimit (): ?int
330
314
{
@@ -333,8 +317,6 @@ public function getRequestLimit(): ?int
333
317
334
318
/**
335
319
* Get the number of requests remaining before you hit the request limit.
336
- *
337
- * @return int|null
338
320
*/
339
321
public function getRequestsRemaining (): ?int
340
322
{
@@ -343,10 +325,8 @@ public function getRequestsRemaining(): ?int
343
325
344
326
/**
345
327
* Fetch the API request details from the last API response.
346
- *
347
- * @param ResponseInterface $response
348
328
*/
349
- protected function updateLimits (ResponseInterface $ response )
329
+ protected function updateLimits (ResponseInterface $ response ): void
350
330
{
351
331
$ requestId = current ($ response ->getHeader ('x-dnsme-requestId ' ));
352
332
if ($ requestId === false ) {
@@ -373,11 +353,7 @@ protected function updateLimits(ResponseInterface $response)
373
353
/**
374
354
* Adds auth headers to requests. These are generated based on the Api Key and the Secret Key.
375
355
*
376
- * @param RequestInterface $request
377
- *
378
356
* @throws \Exception
379
- *
380
- * @return RequestInterface
381
357
*/
382
358
protected function addAuthHeaders (RequestInterface $ request ): RequestInterface
383
359
{
@@ -393,12 +369,8 @@ protected function addAuthHeaders(RequestInterface $request): RequestInterface
393
369
394
370
/**
395
371
* Check if a manager exists with that name in our manager map.
396
- *
397
- * @param $name
398
- *
399
- * @return bool
400
372
*/
401
- protected function hasManager ($ name ): bool
373
+ protected function hasManager (string $ name ): bool
402
374
{
403
375
$ name = strtolower ($ name );
404
376
return array_key_exists ($ name , $ this ->managerMap );
@@ -407,13 +379,9 @@ protected function hasManager($name): bool
407
379
/**
408
380
* Gets the manager with the specified name.
409
381
*
410
- * @param $name
411
- *
412
382
* @throws ManagerNotFoundException
413
- *
414
- * @return AbstractManagerInterface
415
383
*/
416
- protected function getManager ($ name ): AbstractManagerInterface
384
+ protected function getManager (string $ name ): AbstractManagerInterface
417
385
{
418
386
if (! $ this ->hasManager ($ name )) {
419
387
throw new ManagerNotFoundException ();
0 commit comments