1 | <?php |
||
10 | class Client |
||
11 | { |
||
12 | /** |
||
13 | * API base uri |
||
14 | */ |
||
15 | const API_BASE_URI = 'https://api.wit.ai/'; |
||
16 | |||
17 | /* |
||
18 | * API Version |
||
19 | */ |
||
20 | const DEFAULT_API_VERSION = '20160330'; |
||
21 | |||
22 | /** |
||
23 | * Request default timeout |
||
24 | */ |
||
25 | const DEFAULT_TIMEOUT = 5; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | public static $allowedMethod = ['POST', 'GET', 'PUT', 'DELETE']; |
||
31 | |||
32 | /** |
||
33 | * @var string Wit app token |
||
34 | */ |
||
35 | private $accessToken; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $apiVersion; |
||
41 | |||
42 | /** |
||
43 | * @var HttpClient client |
||
44 | */ |
||
45 | private $client; |
||
46 | |||
47 | /** |
||
48 | * @var ResponseInterface|null |
||
49 | */ |
||
50 | private $lastResponse; |
||
51 | |||
52 | 17 | public function __construct($accessToken, HttpClient $httpClient = null, $apiVersion = self::DEFAULT_API_VERSION) |
|
58 | |||
59 | /** |
||
60 | * @param string $uri |
||
61 | * @param array $params |
||
62 | * |
||
63 | * @return ResponseInterface |
||
64 | */ |
||
65 | 1 | public function post($uri, array $params = []) |
|
69 | |||
70 | /** |
||
71 | * @param string $uri |
||
72 | * @param array $params |
||
73 | * |
||
74 | * @return ResponseInterface |
||
75 | */ |
||
76 | 3 | public function get($uri, array $params = []) |
|
80 | |||
81 | /** |
||
82 | * @param string $uri |
||
83 | * @param array $params |
||
84 | * |
||
85 | * @return ResponseInterface |
||
86 | */ |
||
87 | 1 | public function put($uri, array $params = []) |
|
91 | |||
92 | /** |
||
93 | * @param string $uri |
||
94 | * |
||
95 | * @return ResponseInterface |
||
96 | */ |
||
97 | 1 | public function delete($uri) |
|
101 | |||
102 | /** |
||
103 | * @param string $method |
||
104 | * @param string $uri |
||
105 | * @param array $queryParams |
||
|
|||
106 | * @param mixed $postParams |
||
107 | * |
||
108 | * @return ResponseInterface |
||
109 | */ |
||
110 | 15 | public function send($method, $uri, $body = null, array $query = [], array $headers = [], array $options = []) |
|
119 | |||
120 | /** |
||
121 | * Get the last response from the API |
||
122 | * |
||
123 | * @return null|ResponseInterface |
||
124 | */ |
||
125 | 1 | public function getLastResponse() |
|
129 | |||
130 | 1 | public function getHttpClient() |
|
134 | |||
135 | /** |
||
136 | * Get the defaults headers like the Authorization field |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | 14 | private function getDefaultHeaders() |
|
148 | |||
149 | /** |
||
150 | * @param ResponseInterface $response |
||
151 | * |
||
152 | * @throws BadResponseException |
||
153 | */ |
||
154 | 14 | private function validateResponse(ResponseInterface $response) |
|
162 | |||
163 | /** |
||
164 | * @return HttpClient |
||
165 | */ |
||
166 | 1 | private function defaultHttpClient() |
|
170 | |||
171 | /** |
||
172 | * @param $method |
||
173 | * |
||
174 | * @throw \InvalidArgumentException |
||
175 | */ |
||
176 | 15 | private function validateMethod($method) |
|
182 | } |
||
183 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.