1 | <?php |
||
13 | abstract class AbstractApi |
||
14 | { |
||
15 | /** |
||
16 | * @var ClientInterface HTTP-client from Guzzle |
||
17 | */ |
||
18 | protected $client; |
||
19 | |||
20 | /** |
||
21 | * @var SerializerInterface |
||
22 | */ |
||
23 | protected $serializer; |
||
24 | |||
25 | /** |
||
26 | * @var LoggerInterface |
||
27 | */ |
||
28 | protected $logger; |
||
29 | |||
30 | /** |
||
31 | * @var string Authentication token for API |
||
32 | */ |
||
33 | protected $authToken; |
||
34 | |||
35 | /** |
||
36 | * @var string CSRF-token for API |
||
37 | */ |
||
38 | protected $csRfToken; |
||
39 | |||
40 | |||
41 | public function __construct(ClientInterface $httpClient, SerializerInterface $serializer, LoggerInterface $logger) |
||
47 | |||
48 | /** |
||
49 | * Make GET request and return DTO objects |
||
50 | * |
||
51 | * @return array|object |
||
52 | */ |
||
53 | public function getGetJsonData(string $path, array $parameters = [], string $type, DeserializationContext $context = null) |
||
62 | |||
63 | /** |
||
64 | * Make POST request and return DTO objects |
||
65 | * |
||
66 | * @return array|object |
||
67 | */ |
||
68 | public function getPostJsonData(string $path, array $parameters = [], string $type, DeserializationContext $context = null) |
||
77 | |||
78 | /** |
||
79 | * Make GET request and return response body |
||
80 | */ |
||
81 | public function getGetResponseBody($path, array $parameters = []): StreamInterface |
||
85 | |||
86 | /** |
||
87 | * Make POST request and return response body |
||
88 | */ |
||
89 | public function getPostResponseBody(string $path, array $parameters = []): StreamInterface |
||
93 | |||
94 | /** |
||
95 | * @param string $path Request path |
||
96 | * @param array $parameters Key => Value array of query parameters |
||
97 | * |
||
98 | * @return ResponseInterface |
||
99 | * |
||
100 | * @throws NetworkException |
||
101 | */ |
||
102 | private function sendGetRequest(string $path, array $parameters = []): ResponseInterface |
||
108 | |||
109 | /** |
||
110 | * @param string $path Request path |
||
111 | * @param array $parameters Key => Value array of request data |
||
112 | * |
||
113 | * @return ResponseInterface |
||
114 | * |
||
115 | * @throws NetworkException |
||
116 | */ |
||
117 | private function sendPostRequest(string $path, array $parameters = []): ResponseInterface |
||
123 | |||
124 | private function sendRequest(string $method, string $path, array $parameters): ResponseInterface |
||
138 | |||
139 | /** |
||
140 | * @todo refactor with $this->checkResponse() |
||
141 | * |
||
142 | * @param \Exception $e |
||
143 | * |
||
144 | * @throws ForbiddenException |
||
145 | * @throws NotFoundException |
||
146 | * @throws ServerProblemException |
||
147 | * @throws UnauthorizedException |
||
148 | */ |
||
149 | private function processTransferException(\Exception $e): void |
||
166 | |||
167 | /** |
||
168 | * @throws ForbiddenException |
||
169 | * @throws NotFoundException |
||
170 | * @throws ServerProblemException |
||
171 | * @throws UnauthorizedException |
||
172 | */ |
||
173 | private function checkResponse(ResponseInterface $response): void |
||
201 | } |
||
202 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..