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.
@@ 244-272 (lines=29) @@
241
     *
242
     * @return array
243
     */
244
    public function network($id)
245
    {
246
        try {
247
            $response = $this->get(
248
                sprintf(
249
                    '/webservice/smartload/networks/%d',
250
                    $id
251
                ),
252
                [
253
                    'headers' => [
254
                        'Authorization' => sprintf(
255
                            'Bearer %s',
256
                            $this->options['token']
257
                        ),
258
                    ],
259
                ]
260
            );
261
262
            return [
263
                'status'    => 'ok',
264
                'http_code' => $response->getStatusCode(),
265
                'body'      => (string) $response->getBody(),
266
            ];
267
        } catch (\GuzzleHttp\Exception\ClientException $e) {
268
            return $this->clientError($e);
269
        } catch (\GuzzleHttp\Exception\ServerException $e) {
270
            return $this->parseError($e);
271
        }
272
    }
273
274
    /**
275
     * Authenticate and retrieves a list of all available networks.
@@ 281-306 (lines=26) @@
278
     *
279
     * @return array
280
     */
281
    public function networks()
282
    {
283
        try {
284
            $response = $this->get(
285
                '/webservice/smartload/networks',
286
                [
287
                    'headers' => [
288
                        'Authorization' => sprintf(
289
                            'Bearer %s',
290
                            $this->options['token']
291
                        ),
292
                    ],
293
                ]
294
            );
295
296
            return [
297
                'status'    => 'ok',
298
                'http_code' => $response->getStatusCode(),
299
                'body'      => (string) $response->getBody(),
300
            ];
301
        } catch (\GuzzleHttp\Exception\ClientException $e) {
302
            return $this->clientError($e);
303
        } catch (\GuzzleHttp\Exception\ServerException $e) {
304
            return $this->parseError($e);
305
        }
306
    }
307
308
    /**
309
     * Test SmartCall is responding.
@@ 341-369 (lines=29) @@
338
     *
339
     * @return array
340
     */
341
    public function products($id)
342
    {
343
        try {
344
            $response = $this->get(
345
                sprintf(
346
                    '/webservice/smartload/products/%d',
347
                    $id
348
                ),
349
                [
350
                    'headers' => [
351
                        'Authorization' => sprintf(
352
                            'Bearer %s',
353
                            $this->options['token']
354
                        ),
355
                    ],
356
                ]
357
            );
358
359
            return [
360
                'status'    => 'ok',
361
                'http_code' => $response->getStatusCode(),
362
                'body'      => (string) $response->getBody(),
363
            ];
364
        } catch (\GuzzleHttp\Exception\ClientException $e) {
365
            return $this->clientError($e);
366
        } catch (\GuzzleHttp\Exception\ServerException $e) {
367
            return $this->parseError($e);
368
        }
369
    }
370
371
    /**
372
     * Parse the java exception that we receive from Smartcall's Tomcat's.