Passed
Push — master ( 262b3f...86674d )
by Yannick
09:44
created

OnlyofficeHttpClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * (c) Copyright Ascensio System SIA 2025.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
use GuzzleHttp\Client;
18
use GuzzleHttp\Exception\RequestException;
19
use Onlyoffice\DocsIntegrationSdk\Service\Request\HttpClientInterface;
20
21
class OnlyofficeHttpClient implements HttpClientInterface
22
{
23
    private $responseStatusCode;
24
    private $responseBody;
25
26
    public function __construct()
27
    {
28
        $this->responseStatusCode = null;
29
        $this->responseBody = null;
30
    }
31
32
    /**
33
     * Request to Document Server with turn off verification.
34
     *
35
     * @param string $url    - request address
36
     * @param array  $method - request method
37
     * @param array  $opts   - request options
38
     */
39
    public function request($url, $method = 'GET', $opts = [])
40
    {
41
        $httpClient = new Client(['base_uri' => $url]);
42
        try {
43
            $response = $httpClient->request($method, $url, $opts);
44
            $this->responseBody = $response->getBody()->getContents();
45
            $this->responseStatusCode = $response->getStatusCode();
46
        } catch (RequestException $requestException) {
47
            throw new Exception($requestException->getMessage());
48
        }
49
    }
50
51
    /**
52
     * Get the value of responseStatusCode.
53
     */
54
    public function getStatusCode()
55
    {
56
        return $this->responseStatusCode;
57
    }
58
59
    /**
60
     * Get the value of responseBody.
61
     */
62
    public function getBody()
63
    {
64
        return $this->responseBody;
65
    }
66
}
67