Code Duplication    Length = 26-29 lines in 4 locations

src/Client.php 4 locations

@@ 124-149 (lines=26) @@
121
     *
122
     * @return array
123
     */
124
    public function authDelete()
125
    {
126
        try {
127
            $response = $this->delete(
128
                '/webservice/auth',
129
                [
130
                    'headers' => [
131
                        'Authorization' => sprintf(
132
                            'Bearer %s',
133
                            $this->options['token']
134
                        ),
135
                    ],
136
                ]
137
            );
138
139
            return [
140
                'status'    => 'ok',
141
                'http_code' => $response->getStatusCode(),
142
                'body'      => (string) $response->getBody(),
143
            ];
144
        } catch (\GuzzleHttp\Exception\ClientException $e) {
145
            return $this->clientError($e);
146
        } catch (\GuzzleHttp\Exception\ServerException $e) {
147
            return $this->parseError($e);
148
        }
149
    }
150
151
    /**
152
     * Authenticate and invalidates all the user allocated tokens.
@@ 331-359 (lines=29) @@
328
     *
329
     * @return array
330
     */
331
    public function network($id)
332
    {
333
        try {
334
            $response = $this->get(
335
                sprintf(
336
                    '/webservice/smartload/networks/%d',
337
                    $id
338
                ),
339
                [
340
                    'headers' => [
341
                        'Authorization' => sprintf(
342
                            'Bearer %s',
343
                            $this->options['token']
344
                        ),
345
                    ],
346
                ]
347
            );
348
349
            return [
350
                'status'    => 'ok',
351
                'http_code' => $response->getStatusCode(),
352
                'body'      => (string) $response->getBody(),
353
            ];
354
        } catch (\GuzzleHttp\Exception\ClientException $e) {
355
            return $this->clientError($e);
356
        } catch (\GuzzleHttp\Exception\ServerException $e) {
357
            return $this->parseError($e);
358
        }
359
    }
360
361
    /**
362
     * Authenticate and retrieves a list of all available networks.
@@ 368-393 (lines=26) @@
365
     *
366
     * @return array
367
     */
368
    public function networks()
369
    {
370
        try {
371
            $response = $this->get(
372
                '/webservice/smartload/networks',
373
                [
374
                    'headers' => [
375
                        'Authorization' => sprintf(
376
                            'Bearer %s',
377
                            $this->options['token']
378
                        ),
379
                    ],
380
                ]
381
            );
382
383
            return [
384
                'status'    => 'ok',
385
                'http_code' => $response->getStatusCode(),
386
                'body'      => (string) $response->getBody(),
387
            ];
388
        } catch (\GuzzleHttp\Exception\ClientException $e) {
389
            return $this->clientError($e);
390
        } catch (\GuzzleHttp\Exception\ServerException $e) {
391
            return $this->parseError($e);
392
        }
393
    }
394
395
    /**
396
     * Test SmartCall is responding.
@@ 428-456 (lines=29) @@
425
     *
426
     * @return array
427
     */
428
    public function products($id)
429
    {
430
        try {
431
            $response = $this->get(
432
                sprintf(
433
                    '/webservice/smartload/products/%d',
434
                    $id
435
                ),
436
                [
437
                    'headers' => [
438
                        'Authorization' => sprintf(
439
                            'Bearer %s',
440
                            $this->options['token']
441
                        ),
442
                    ],
443
                ]
444
            );
445
446
            return [
447
                'status'    => 'ok',
448
                'http_code' => $response->getStatusCode(),
449
                'body'      => (string) $response->getBody(),
450
            ];
451
        } catch (\GuzzleHttp\Exception\ClientException $e) {
452
            return $this->clientError($e);
453
        } catch (\GuzzleHttp\Exception\ServerException $e) {
454
            return $this->parseError($e);
455
        }
456
    }
457
458
    /**
459
     * Parse the java exception that we receive from Smartcall's Tomcat's.