1 | <?php |
||
17 | class ApiRequester |
||
18 | { |
||
19 | /** |
||
20 | * @var \Vindi\Http\Client |
||
21 | */ |
||
22 | public $client; |
||
23 | |||
24 | /** |
||
25 | * @var ResponseInterface |
||
26 | */ |
||
27 | public $lastResponse; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | public $lastOptions; |
||
33 | |||
34 | /** |
||
35 | * ApiRequester constructor. |
||
36 | */ |
||
37 | 458 | public function __construct() |
|
41 | |||
42 | /** |
||
43 | * @param string $method HTTP Method. |
||
44 | * @param string $endpoint Relative to API base path. |
||
45 | * @param array $options Options for the request. |
||
46 | * |
||
47 | * @return mixed |
||
48 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
49 | * @throws \Vindi\Exceptions\RateLimitException |
||
50 | * @throws \Vindi\Exceptions\RequestException |
||
51 | */ |
||
52 | 10 | public function request($method, $endpoint, array $options = []) |
|
63 | |||
64 | /** |
||
65 | * @param ResponseInterface $response |
||
66 | * |
||
67 | * @return object |
||
68 | * @throws RateLimitException |
||
69 | * @throws \Vindi\Exceptions\RequestException |
||
70 | */ |
||
71 | 10 | public function response(ResponseInterface $response) |
|
90 | |||
91 | /** |
||
92 | * @param ResponseInterface $response |
||
93 | 10 | * |
|
94 | * @return $this |
||
95 | 10 | * @throws RateLimitException |
|
96 | 2 | */ |
|
97 | private function checkRateLimit(ResponseInterface $response) |
||
105 | |||
106 | /** |
||
107 | * @param ResponseInterface $response |
||
108 | * @param mixed $data |
||
109 | 8 | * |
|
110 | * @return $this |
||
111 | 8 | * @throws \Vindi\Exceptions\RequestException |
|
112 | */ |
||
113 | 8 | private function checkForErrors(ResponseInterface $response, $data) |
|
132 | } |
||
133 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: