Code Duplication    Length = 33-35 lines in 2 locations

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

@@ 229-261 (lines=33) @@
226
     * @throws UnauthorizedException
227
     * @throws PartnerRequestException
228
     */
229
    protected function sendRequest($method, $uri, array $options = [])
230
    {
231
        try {
232
            $response = $this->getClient()->request($method, $uri, $options);
233
        } catch (ClientException $ex) {
234
            $result = $ex->getResponse();
235
            $code = $result->getStatusCode();
236
            $message = $result->getReasonPhrase();
237
238
            $body = $result->getBody();
239
            if ($body) {
240
                $jsonBody = json_decode($body);
241
                if ($jsonBody && isset($jsonBody->error) && isset($jsonBody->error->message)) {
242
                    $message = $jsonBody->error->message;
243
                }
244
            }
245
246
            if ($code === 403) {
247
                throw new ForbiddenException($message);
248
            }
249
250
            if ($code === 401) {
251
                throw new UnauthorizedException($message);
252
            }
253
254
            throw new PartnerRequestException(
255
                'Service responded with error code: "' . $code . '" and message: "' . $message . '"',
256
                $code
257
            );
258
        }
259
260
        return $response;
261
    }
262
263
    /**
264
     * Get OAuth data for header request

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

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