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

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