Code Duplication    Length = 16-16 lines in 6 locations

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

@@ 109-124 (lines=16) @@
106
     * @throws InvalidResponseException
107
     * @throws UserNotFoundException
108
     */
109
    public function getUserSubscribersByLogin(string $login): array
110
    {
111
        $this->logger->debug('Trying to get user subscribers by login', ['login' => $login]);
112
113
        try {
114
            $usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscribers', [], true);
115
        } catch (RequestException $e) {
116
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
117
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
118
            } else {
119
                throw $e;
120
            }
121
        }
122
123
        return $this->getUsersFromList($usersList);
124
    }
125
126
    /**
127
     * Get user subscribers by user id
@@ 137-152 (lines=16) @@
134
     * @throws InvalidResponseException
135
     * @throws UserNotFoundException
136
     */
137
    public function getUserSubscribersById(int $id): array
138
    {
139
        $this->logger->debug('Trying to get user subscribers by id', ['id' => $id]);
140
141
        try {
142
            $usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscribers', [], true);
143
        } catch (RequestException $e) {
144
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
145
                throw new UserNotFoundException('User not found', 0, $e, $id);
146
            } else {
147
                throw $e;
148
            }
149
        }
150
151
        return $this->getUsersFromList($usersList);
152
    }
153
154
    /**
155
     * Get user subscriptions by user login
@@ 165-180 (lines=16) @@
162
     * @throws InvalidResponseException
163
     * @throws UserNotFoundException
164
     */
165
    public function getUserSubscriptionsByLogin(string $login): array
166
    {
167
        $this->logger->debug('Trying to get user subscriptions by login', ['login' => $login]);
168
169
        try {
170
            $usersList = $this->getGetRequestData('/api/user/'.urlencode($login).'/subscriptions', [], true);
171
        } catch (RequestException $e) {
172
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
173
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
174
            } else {
175
                throw $e;
176
            }
177
        }
178
179
        return $this->getUsersFromList($usersList);
180
    }
181
182
    /**
183
     * Get user subscriptions by user id
@@ 193-208 (lines=16) @@
190
     * @throws InvalidResponseException
191
     * @throws UserNotFoundException
192
     */
193
    public function getUserSubscriptionsById(int $id): array
194
    {
195
        $this->logger->debug('Trying to get user subscriptions by id', ['id' => $id]);
196
197
        try {
198
            $usersList = $this->getGetRequestData('/api/user/id/'.(int) $id.'/subscriptions', [], true);
199
        } catch (RequestException $e) {
200
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
201
                throw new UserNotFoundException('User not found', 0, $e, $id);
202
            } else {
203
                throw $e;
204
            }
205
        }
206
207
        return $this->getUsersFromList($usersList);
208
    }
209
210
    /**
211
     * Get single user by login
@@ 220-235 (lines=16) @@
217
     * @throws UserNotFoundException
218
     * @throws RequestException
219
     */
220
    public function getUserByLogin(string $login): User
221
    {
222
        $this->logger->debug('Trying to get user by login', ['login' => $login]);
223
224
        try {
225
            $userInfo = $this->getGetRequestData('/api/user/login/'.urlencode($login), [], true);
226
        } catch (RequestException $e) {
227
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
228
                throw new UserNotFoundException('User not found', 0, $e, null, $login);
229
            } else {
230
                throw $e;
231
            }
232
        }
233
234
        return $this->getUserFromUserInfo($userInfo);
235
    }
236
237
    /**
238
     * Get single user by id
@@ 247-262 (lines=16) @@
244
     * @throws UserNotFoundException
245
     * @throws RequestException
246
     */
247
    public function getUserById(int $id): User
248
    {
249
        $this->logger->debug('Trying to get user by id', ['id' => $id]);
250
251
        try {
252
            $userInfo = $this->getGetRequestData('/api/user/id/'.$id, [], true);
253
        } catch (RequestException $e) {
254
            if (Response::HTTP_NOT_FOUND === $e->getResponse()->getStatusCode()) {
255
                throw new UserNotFoundException('User not found', 0, $e, $id);
256
            } else {
257
                throw $e;
258
            }
259
        }
260
261
        return $this->getUserFromUserInfo($userInfo);
262
    }
263
264
    /**
265
     * Finds and updates or create new user from API response data