Code Duplication    Length = 33-35 lines in 2 locations

src/Yandex/Market/Partner/PartnerClient.php 1 location

@@ 211-243 (lines=33) @@
208
     * @throws UnauthorizedException
209
     * @throws PartnerRequestException
210
     */
211
    protected function sendRequest($method, $uri, array $options = [])
212
    {
213
        try {
214
            $response = $this->getClient()->request($method, $uri, $options);
215
        } catch (ClientException $ex) {
216
            $result = $ex->getResponse();
217
            $code = $result->getStatusCode();
218
            $message = $result->getReasonPhrase();
219
220
            $body = $result->getBody();
221
            if ($body) {
222
                $jsonBody = json_decode($body);
223
                if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) {
224
                    $message = $jsonBody->error->message;
225
                }
226
            }
227
228
            if ($code === 403) {
229
                throw new ForbiddenException($message);
230
            }
231
232
            if ($code === 401) {
233
                throw new UnauthorizedException($message);
234
            }
235
236
            throw new PartnerRequestException(
237
                'Service responded with error code: "' . $code . '" and message: "' . $message . '"',
238
                $code
239
            );
240
        }
241
242
        return $response;
243
    }
244
245
    /**
246
     * Get OAuth data for header request

src/Yandex/Market/Content/ContentClient.php 1 location

@@ 117-151 (lines=35) @@
114
     * @throws UnauthorizedException
115
     * @throws ContentRequestException
116
     */
117
    protected function sendRequest($method, $uri, array $options = [])
118
    {
119
        try {
120
            $response = $this->getClient()->request($method, $uri, $options);
121
        } catch (ClientException $ex) {
122
            $result = $ex->getResponse();
123
            $code = $result->getStatusCode();
124
            $message = $result->getReasonPhrase();
125
126
            $body = $result->getBody();
127
            if ($body) {
128
                $jsonBody = json_decode($body);
129
                if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) {
130
                    $message = $jsonBody->error->message;
131
                }
132
            }
133
134
            if ($code === 403) {
135
                throw new ForbiddenException($message);
136
            }
137
138
            if ($code === 401) {
139
                throw new UnauthorizedException($message);
140
            }
141
142
            throw new ContentRequestException(
143
                'Service responded with error code: "' . $code . '" and message: "' . $message . '"',
144
                $code
145
            );
146
        }
147
        // @note: Finally? php >= 5.5
148
        $this->setLimits($response->getHeaders());
149
150
        return $response;
151
    }
152
153
    private function setLimits($headers)
154
    {