Code Duplication    Length = 14-14 lines in 6 locations

src/Skobkin/Bundle/PointToolsBundle/Service/UserApi.php 6 locations

@@ 118-131 (lines=14) @@
115
     * @throws InvalidResponseException
116
     * @throws UserNotFoundException
117
     */
118
    public function getUserSubscribersByLogin(string $login): array
119
    {
120
        try {
121
            $usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscribers', [], true);
122
        } catch (RequestException $e) {
123
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
124
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
125
            } else {
126
                throw $e;
127
            }
128
        }
129
130
        return $this->getUsersFromList($usersList);
131
    }
132
133
    /**
134
     * Get user subscribers by user id
@@ 144-157 (lines=14) @@
141
     * @throws InvalidResponseException
142
     * @throws UserNotFoundException
143
     */
144
    public function getUserSubscribersById(int $id): array
145
    {
146
        try {
147
            $usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscribers', [], true);
148
        } catch (RequestException $e) {
149
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
150
                throw new UserNotFoundException('User not found', 0, $e, $id);
151
            } else {
152
                throw $e;
153
            }
154
        }
155
156
        return $this->getUsersFromList($usersList);
157
    }
158
159
    /**
160
     * Get user subscriptions by user login
@@ 170-183 (lines=14) @@
167
     * @throws InvalidResponseException
168
     * @throws UserNotFoundException
169
     */
170
    public function getUserSubscriptionsByLogin(string $login): array
171
    {
172
        try {
173
            $usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscriptions', [], true);
174
        } catch (RequestException $e) {
175
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
176
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
177
            } else {
178
                throw $e;
179
            }
180
        }
181
182
        return $this->getUsersFromList($usersList);
183
    }
184
185
    /**
186
     * Get user subscriptions by user id
@@ 196-209 (lines=14) @@
193
     * @throws InvalidResponseException
194
     * @throws UserNotFoundException
195
     */
196
    public function getUserSubscriptionsById(int $id): array
197
    {
198
        try {
199
            $usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscriptions', [], true);
200
        } catch (RequestException $e) {
201
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
202
                throw new UserNotFoundException('User not found', 0, $e, $id);
203
            } else {
204
                throw $e;
205
            }
206
        }
207
208
        return $this->getUsersFromList($usersList);
209
    }
210
211
    /**
212
     * Get single user by login
@@ 221-234 (lines=14) @@
218
     * @throws UserNotFoundException
219
     * @throws RequestException
220
     */
221
    public function getUserByLogin(string $login): User
222
    {
223
        try {
224
            $userInfo = $this->getGetRequestData('/api/user/login/'.urlencode($login), [], true);
225
        } catch (RequestException $e) {
226
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
227
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
228
            } else {
229
                throw $e;
230
            }
231
        }
232
233
        return $this->getUserFromUserInfo($userInfo);
234
    }
235
236
    /**
237
     * Get single user by id
@@ 246-259 (lines=14) @@
243
     * @throws UserNotFoundException
244
     * @throws RequestException
245
     */
246
    public function getUserById(int $id): User
247
    {
248
        try {
249
            $userInfo = $this->getGetRequestData('/api/user/id/'.$id, [], true);
250
        } catch (RequestException $e) {
251
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
252
                throw new UserNotFoundException('User not found', 0, $e, $id);
253
            } else {
254
                throw $e;
255
            }
256
        }
257
258
        return $this->getUserFromUserInfo($userInfo);
259
    }
260
261
    /**
262
     * Finds and updates or create new user from API response data