Code Duplication    Length = 23-26 lines in 11 locations

src/Client.php 4 locations

@@ 107-129 (lines=23) @@
104
     *
105
     * @return array
106
     */
107
    public function auth()
108
    {
109
        try {
110
            $response = $this->post(
111
                '/webservice/auth',
112
                [
113
                    'headers' => [
114
                        'Authorization' => $this->bearerOrBasic(),
115
                    ],
116
                ]
117
            );
118
119
            return [
120
                'status'    => 'ok',
121
                'http_code' => $response->getStatusCode(),
122
                'body'      => (string) $response->getBody(),
123
            ];
124
        } catch (\GuzzleHttp\Exception\ClientException $e) {
125
            return $this->clientError($e);
126
        } catch (\GuzzleHttp\Exception\ServerException $e) {
127
            return $this->parseError($e);
128
        }
129
    }
130
131
    /**
132
     * Authenticate and invalidates all the user allocated tokens.
@@ 138-160 (lines=23) @@
135
     *
136
     * @return array
137
     */
138
    public function authDelete()
139
    {
140
        try {
141
            $response = $this->delete(
142
                '/webservice/auth',
143
                [
144
                    'headers' => [
145
                        'Authorization' => $this->bearerOrBasic(),
146
                    ],
147
                ]
148
            );
149
150
            return [
151
                'status'    => 'ok',
152
                'http_code' => $response->getStatusCode(),
153
                'body'      => (string) $response->getBody(),
154
            ];
155
        } catch (\GuzzleHttp\Exception\ClientException $e) {
156
            return $this->clientError($e);
157
        } catch (\GuzzleHttp\Exception\ServerException $e) {
158
            return $this->parseError($e);
159
        }
160
    }
161
162
    /**
163
     * Authenticate and invalidates all the user allocated tokens.
@@ 169-191 (lines=23) @@
166
     *
167
     * @return array
168
     */
169
    public function authFlush()
170
    {
171
        try {
172
            $response = $this->delete(
173
                '/webservice/auth/token',
174
                [
175
                    'headers' => [
176
                        'Authorization' => $this->bearerOrBasic(),
177
                    ],
178
                ]
179
            );
180
181
            return [
182
                'status'    => 'ok',
183
                'http_code' => $response->getStatusCode(),
184
                'body'      => (string) $response->getBody(),
185
            ];
186
        } catch (\GuzzleHttp\Exception\ClientException $e) {
187
            return $this->clientError($e);
188
        } catch (\GuzzleHttp\Exception\ServerException $e) {
189
            return $this->parseError($e);
190
        }
191
    }
192
193
    /**
194
     * Authenticate and gets the number of available session tokens.
@@ 200-222 (lines=23) @@
197
     *
198
     * @return array
199
     */
200
    public function authToken()
201
    {
202
        try {
203
            $response = $this->get(
204
                '/webservice/auth/token',
205
                [
206
                    'headers' => [
207
                        'Authorization' => $this->bearerOrBasic(),
208
                    ],
209
                ]
210
            );
211
212
            return [
213
                'status'    => 'ok',
214
                'http_code' => $response->getStatusCode(),
215
                'body'      => (string) $response->getBody(),
216
            ];
217
        } catch (\GuzzleHttp\Exception\ClientException $e) {
218
            return $this->clientError($e);
219
        } catch (\GuzzleHttp\Exception\ServerException $e) {
220
            return $this->parseError($e);
221
        }
222
    }
223
224
    /**
225
     * Test SmartCall is responding.

src/Traits/SmartLoad.php 6 locations

@@ 26-51 (lines=26) @@
23
     *
24
     * @return array
25
     */
26
    public function balance($dealerMsisdn)
27
    {
28
        try {
29
            $response = $this->get(
30
                sprintf(
31
                    '/webservice/smartload/balance/%s',
32
                    $dealerMsisdn
33
                ),
34
                [
35
                    'headers' => [
36
                        'Authorization' => $this->bearerOrBasic(),
37
                    ],
38
                ]
39
            );
40
41
            return [
42
                'status'    => 'ok',
43
                'http_code' => $response->getStatusCode(),
44
                'body'      => (string) $response->getBody(),
45
            ];
46
        } catch (\GuzzleHttp\Exception\ClientException $e) {
47
            return $this->clientError($e);
48
        } catch (\GuzzleHttp\Exception\ServerException $e) {
49
            return $this->parseError($e);
50
        }
51
    }
52
53
    /**
54
     * Authenticate and request period based cashup reports.
@@ 102-127 (lines=26) @@
99
     *
100
     * @return array
101
     */
102
    public function cashupToday($dealerMsisdn)
103
    {
104
        try {
105
            $response = $this->get(
106
                sprintf(
107
                    '/webservice/smartload/cashup/%s',
108
                    $dealerMsisdn
109
                ),
110
                [
111
                    'headers' => [
112
                        'Authorization' => $this->bearerOrBasic(),
113
                    ],
114
                ]
115
            );
116
117
            return [
118
                'status'    => 'ok',
119
                'http_code' => $response->getStatusCode(),
120
                'body'      => (string) $response->getBody(),
121
            ];
122
        } catch (\GuzzleHttp\Exception\ClientException $e) {
123
            return $this->clientError($e);
124
        } catch (\GuzzleHttp\Exception\ServerException $e) {
125
            return $this->parseError($e);
126
        }
127
    }
128
129
    /**
130
     * Authenticate and request to transfer funds from one Smartload account to another.
@@ 178-203 (lines=26) @@
175
     *
176
     * @return array
177
     */
178
    public function network($id)
179
    {
180
        try {
181
            $response = $this->get(
182
                sprintf(
183
                    '/webservice/smartload/networks/%d',
184
                    $id
185
                ),
186
                [
187
                    'headers' => [
188
                        'Authorization' => $this->bearerOrBasic(),
189
                    ],
190
                ]
191
            );
192
193
            return [
194
                'status'    => 'ok',
195
                'http_code' => $response->getStatusCode(),
196
                'body'      => (string) $response->getBody(),
197
            ];
198
        } catch (\GuzzleHttp\Exception\ClientException $e) {
199
            return $this->clientError($e);
200
        } catch (\GuzzleHttp\Exception\ServerException $e) {
201
            return $this->parseError($e);
202
        }
203
    }
204
205
    /**
206
     * Authenticate and retrieves a list of all available networks.
@@ 212-234 (lines=23) @@
209
     *
210
     * @return array
211
     */
212
    public function networks()
213
    {
214
        try {
215
            $response = $this->get(
216
                '/webservice/smartload/networks',
217
                [
218
                    'headers' => [
219
                        'Authorization' => $this->bearerOrBasic(),
220
                    ],
221
                ]
222
            );
223
224
            return [
225
                'status'    => 'ok',
226
                'http_code' => $response->getStatusCode(),
227
                'body'      => (string) $response->getBody(),
228
            ];
229
        } catch (\GuzzleHttp\Exception\ClientException $e) {
230
            return $this->clientError($e);
231
        } catch (\GuzzleHttp\Exception\ServerException $e) {
232
            return $this->parseError($e);
233
        }
234
    }
235
236
    /**
237
     * Authenticate and recharge prevend request.
@@ 307-332 (lines=26) @@
304
     *
305
     * @return array
306
     */
307
    public function products($id)
308
    {
309
        try {
310
            $response = $this->get(
311
                sprintf(
312
                    '/webservice/smartload/products/%d',
313
                    $id
314
                ),
315
                [
316
                    'headers' => [
317
                        'Authorization' => $this->bearerOrBasic(),
318
                    ],
319
                ]
320
            );
321
322
            return [
323
                'status'    => 'ok',
324
                'http_code' => $response->getStatusCode(),
325
                'body'      => (string) $response->getBody(),
326
            ];
327
        } catch (\GuzzleHttp\Exception\ClientException $e) {
328
            return $this->clientError($e);
329
        } catch (\GuzzleHttp\Exception\ServerException $e) {
330
            return $this->parseError($e);
331
        }
332
    }
333
334
    /**
335
     * Authenticate and checks if the provided ID (MSISDN) is registered with Smartload.
@@ 343-368 (lines=26) @@
340
     *
341
     * @return array
342
     */
343
    public function registered($dealerMsisdn)
344
    {
345
        try {
346
            $response = $this->get(
347
                sprintf(
348
                    '/webservice/smartload/registered/%s',
349
                    $dealerMsisdn
350
                ),
351
                [
352
                    'headers' => [
353
                        'Authorization' => $this->bearerOrBasic(),
354
                    ],
355
                ]
356
            );
357
358
            return [
359
                'status'    => 'ok',
360
                'http_code' => $response->getStatusCode(),
361
                'body'      => (string) $response->getBody(),
362
            ];
363
        } catch (\GuzzleHttp\Exception\ClientException $e) {
364
            return $this->clientError($e);
365
        } catch (\GuzzleHttp\Exception\ServerException $e) {
366
            return $this->parseError($e);
367
        }
368
    }
369
}
370

src/Traits/SmartRica.php 1 location

@@ 55-77 (lines=23) @@
52
        }
53
    }
54
55
    public function registrations()
56
    {
57
        try {
58
            $response = $this->post(
59
                '/webservice/smartrica/registrations',
60
                [
61
                    'headers' => [
62
                        'Authorization' => $this->bearerOrBasic(),
63
                    ],
64
                ]
65
            );
66
67
            return [
68
                'status'    => 'ok',
69
                'http_code' => $response->getStatusCode(),
70
                'body'      => (string) $response->getBody(),
71
            ];
72
        } catch (\GuzzleHttp\Exception\ClientException $e) {
73
            return $this->clientError($e);
74
        } catch (\GuzzleHttp\Exception\ServerException $e) {
75
            return $this->parseError($e);
76
        }
77
    }
78
}
79