Code Duplication    Length = 23-26 lines in 10 locations

src/Client.php 10 locations

@@ 101-123 (lines=23) @@
98
     *
99
     * @return array
100
     */
101
    public function auth()
102
    {
103
        try {
104
            $response = $this->post(
105
                '/webservice/auth',
106
                [
107
                    'headers' => [
108
                        'Authorization' => $this->bearerOrBasic(),
109
                    ],
110
                ]
111
            );
112
113
            return [
114
                'status'    => 'ok',
115
                'http_code' => $response->getStatusCode(),
116
                'body'      => (string) $response->getBody(),
117
            ];
118
        } catch (\GuzzleHttp\Exception\ClientException $e) {
119
            return $this->clientError($e);
120
        } catch (\GuzzleHttp\Exception\ServerException $e) {
121
            return $this->parseError($e);
122
        }
123
    }
124
125
    /**
126
     * Authenticate and invalidates all the user allocated tokens.
@@ 132-154 (lines=23) @@
129
     *
130
     * @return array
131
     */
132
    public function authDelete()
133
    {
134
        try {
135
            $response = $this->delete(
136
                '/webservice/auth',
137
                [
138
                    'headers' => [
139
                        'Authorization' => $this->bearerOrBasic(),
140
                    ],
141
                ]
142
            );
143
144
            return [
145
                'status'    => 'ok',
146
                'http_code' => $response->getStatusCode(),
147
                'body'      => (string) $response->getBody(),
148
            ];
149
        } catch (\GuzzleHttp\Exception\ClientException $e) {
150
            return $this->clientError($e);
151
        } catch (\GuzzleHttp\Exception\ServerException $e) {
152
            return $this->parseError($e);
153
        }
154
    }
155
156
    /**
157
     * Authenticate and invalidates all the user allocated tokens.
@@ 163-185 (lines=23) @@
160
     *
161
     * @return array
162
     */
163
    public function authFlush()
164
    {
165
        try {
166
            $response = $this->delete(
167
                '/webservice/auth/token',
168
                [
169
                    'headers' => [
170
                        'Authorization' => $this->bearerOrBasic(),
171
                    ],
172
                ]
173
            );
174
175
            return [
176
                'status'    => 'ok',
177
                'http_code' => $response->getStatusCode(),
178
                'body'      => (string) $response->getBody(),
179
            ];
180
        } catch (\GuzzleHttp\Exception\ClientException $e) {
181
            return $this->clientError($e);
182
        } catch (\GuzzleHttp\Exception\ServerException $e) {
183
            return $this->parseError($e);
184
        }
185
    }
186
187
    /**
188
     * Authenticate and gets the number of available session tokens.
@@ 194-216 (lines=23) @@
191
     *
192
     * @return array
193
     */
194
    public function authToken()
195
    {
196
        try {
197
            $response = $this->get(
198
                '/webservice/auth/token',
199
                [
200
                    'headers' => [
201
                        'Authorization' => $this->bearerOrBasic(),
202
                    ],
203
                ]
204
            );
205
206
            return [
207
                'status'    => 'ok',
208
                'http_code' => $response->getStatusCode(),
209
                'body'      => (string) $response->getBody(),
210
            ];
211
        } catch (\GuzzleHttp\Exception\ClientException $e) {
212
            return $this->clientError($e);
213
        } catch (\GuzzleHttp\Exception\ServerException $e) {
214
            return $this->parseError($e);
215
        }
216
    }
217
218
    /**
219
     * Authenticate and request period based cashup reports.
@@ 267-292 (lines=26) @@
264
     *
265
     * @return array
266
     */
267
    public function balance($dealerMsisdn)
268
    {
269
        try {
270
            $response = $this->get(
271
                sprintf(
272
                    '/webservice/smartload/balance/%s',
273
                    $dealerMsisdn
274
                ),
275
                [
276
                    'headers' => [
277
                        'Authorization' => $this->bearerOrBasic(),
278
                    ],
279
                ]
280
            );
281
282
            return [
283
                'status'    => 'ok',
284
                'http_code' => $response->getStatusCode(),
285
                'body'      => (string) $response->getBody(),
286
            ];
287
        } catch (\GuzzleHttp\Exception\ClientException $e) {
288
            return $this->clientError($e);
289
        } catch (\GuzzleHttp\Exception\ServerException $e) {
290
            return $this->parseError($e);
291
        }
292
    }
293
294
    /**
295
     * Authenticate and request current day cashup report.
@@ 303-328 (lines=26) @@
300
     *
301
     * @return array
302
     */
303
    public function cashupToday($dealerMsisdn)
304
    {
305
        try {
306
            $response = $this->get(
307
                sprintf(
308
                    '/webservice/smartload/cashup/%s',
309
                    $dealerMsisdn
310
                ),
311
                [
312
                    'headers' => [
313
                        'Authorization' => $this->bearerOrBasic(),
314
                    ],
315
                ]
316
            );
317
318
            return [
319
                'status'    => 'ok',
320
                'http_code' => $response->getStatusCode(),
321
                'body'      => (string) $response->getBody(),
322
            ];
323
        } catch (\GuzzleHttp\Exception\ClientException $e) {
324
            return $this->clientError($e);
325
        } catch (\GuzzleHttp\Exception\ServerException $e) {
326
            return $this->parseError($e);
327
        }
328
    }
329
330
    /**
331
     * Authenticate and request to transfer funds from one Smartload account to another.
@@ 379-404 (lines=26) @@
376
     *
377
     * @return array
378
     */
379
    public function network($id)
380
    {
381
        try {
382
            $response = $this->get(
383
                sprintf(
384
                    '/webservice/smartload/networks/%d',
385
                    $id
386
                ),
387
                [
388
                    'headers' => [
389
                        'Authorization' => $this->bearerOrBasic(),
390
                    ],
391
                ]
392
            );
393
394
            return [
395
                'status'    => 'ok',
396
                'http_code' => $response->getStatusCode(),
397
                'body'      => (string) $response->getBody(),
398
            ];
399
        } catch (\GuzzleHttp\Exception\ClientException $e) {
400
            return $this->clientError($e);
401
        } catch (\GuzzleHttp\Exception\ServerException $e) {
402
            return $this->parseError($e);
403
        }
404
    }
405
406
    /**
407
     * Authenticate and retrieves a list of all available networks.
@@ 413-435 (lines=23) @@
410
     *
411
     * @return array
412
     */
413
    public function networks()
414
    {
415
        try {
416
            $response = $this->get(
417
                '/webservice/smartload/networks',
418
                [
419
                    'headers' => [
420
                        'Authorization' => $this->bearerOrBasic(),
421
                    ],
422
                ]
423
            );
424
425
            return [
426
                'status'    => 'ok',
427
                'http_code' => $response->getStatusCode(),
428
                'body'      => (string) $response->getBody(),
429
            ];
430
        } catch (\GuzzleHttp\Exception\ClientException $e) {
431
            return $this->clientError($e);
432
        } catch (\GuzzleHttp\Exception\ServerException $e) {
433
            return $this->parseError($e);
434
        }
435
    }
436
437
    /**
438
     * Test SmartCall is responding.
@@ 470-495 (lines=26) @@
467
     *
468
     * @return array
469
     */
470
    public function products($id)
471
    {
472
        try {
473
            $response = $this->get(
474
                sprintf(
475
                    '/webservice/smartload/products/%d',
476
                    $id
477
                ),
478
                [
479
                    'headers' => [
480
                        'Authorization' => $this->bearerOrBasic(),
481
                    ],
482
                ]
483
            );
484
485
            return [
486
                'status'    => 'ok',
487
                'http_code' => $response->getStatusCode(),
488
                'body'      => (string) $response->getBody(),
489
            ];
490
        } catch (\GuzzleHttp\Exception\ClientException $e) {
491
            return $this->clientError($e);
492
        } catch (\GuzzleHttp\Exception\ServerException $e) {
493
            return $this->parseError($e);
494
        }
495
    }
496
497
    /**
498
     * Authenticate and checks if the provided ID (MSISDN) is registered with Smartload.
@@ 506-531 (lines=26) @@
503
     *
504
     * @return array
505
     */
506
    public function registered($dealerMsisdn)
507
    {
508
        try {
509
            $response = $this->get(
510
                sprintf(
511
                    '/webservice/smartload/registered/%s',
512
                    $dealerMsisdn
513
                ),
514
                [
515
                    'headers' => [
516
                        'Authorization' => $this->bearerOrBasic(),
517
                    ],
518
                ]
519
            );
520
521
            return [
522
                'status'    => 'ok',
523
                'http_code' => $response->getStatusCode(),
524
                'body'      => (string) $response->getBody(),
525
            ];
526
        } catch (\GuzzleHttp\Exception\ClientException $e) {
527
            return $this->clientError($e);
528
        } catch (\GuzzleHttp\Exception\ServerException $e) {
529
            return $this->parseError($e);
530
        }
531
    }
532
533
    /**
534
     * Parse the java exception that we receive from Smartcall's Tomcat's.