Code Duplication    Length = 32-32 lines in 3 locations

src/Client.php 3 locations

@@ 84-115 (lines=32) @@
81
     *
82
     * @return array
83
     */
84
    public function auth($username, $password)
85
    {
86
        try {
87
            $response = $this->post(
88
                '/webservice/auth',
89
                [
90
                    'headers' => [
91
                        'Authorization' => sprintf(
92
                            'Basic %s',
93
                            base64_encode(
94
                                sprintf(
95
                                    '%s:%s',
96
                                    $username,
97
                                    $password
98
                                )
99
                            )
100
                        ),
101
                    ],
102
                ]
103
            );
104
105
            return [
106
                'status'    => 'ok',
107
                'http_code' => $response->getStatusCode(),
108
                'body'      => (string) $response->getBody(),
109
            ];
110
        } catch (\GuzzleHttp\Exception\ClientException $e) {
111
            return $this->clientError($e);
112
        } catch (\GuzzleHttp\Exception\ServerException $e) {
113
            return $this->parseError($e);
114
        }
115
    }
116
117
    /**
118
     * Authenticate and invalidates all the user allocated tokens.
@@ 161-192 (lines=32) @@
158
     *
159
     * @return array
160
     */
161
    public function authFlush($username, $password)
162
    {
163
        try {
164
            $response = $this->delete(
165
                '/webservice/auth/token',
166
                [
167
                    'headers' => [
168
                        'Authorization' => sprintf(
169
                            'Basic %s',
170
                            base64_encode(
171
                                sprintf(
172
                                    '%s:%s',
173
                                    $username,
174
                                    $password
175
                                )
176
                            )
177
                        ),
178
                    ],
179
                ]
180
            );
181
182
            return [
183
                'status'    => 'ok',
184
                'http_code' => $response->getStatusCode(),
185
                'body'      => (string) $response->getBody(),
186
            ];
187
        } catch (\GuzzleHttp\Exception\ClientException $e) {
188
            return $this->clientError($e);
189
        } catch (\GuzzleHttp\Exception\ServerException $e) {
190
            return $this->parseError($e);
191
        }
192
    }
193
194
    /**
195
     * Authenticate and gets the number of available session tokens.
@@ 204-235 (lines=32) @@
201
     *
202
     * @return array
203
     */
204
    public function authToken($username, $password)
205
    {
206
        try {
207
            $response = $this->get(
208
                '/webservice/auth/token',
209
                [
210
                    'headers' => [
211
                        'Authorization' => sprintf(
212
                            'Basic %s',
213
                            base64_encode(
214
                                sprintf(
215
                                    '%s:%s',
216
                                    $username,
217
                                    $password
218
                                )
219
                            )
220
                        ),
221
                    ],
222
                ]
223
            );
224
225
            return [
226
                'status'    => 'ok',
227
                'http_code' => $response->getStatusCode(),
228
                'body'      => (string) $response->getBody(),
229
            ];
230
        } catch (\GuzzleHttp\Exception\ClientException $e) {
231
            return $this->clientError($e);
232
        } catch (\GuzzleHttp\Exception\ServerException $e) {
233
            return $this->parseError($e);
234
        }
235
    }
236
237
    /**
238
     * Authenticate and retrieves a list of all available networks.