Code Duplication    Length = 33-35 lines in 2 locations

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
    {

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