1 | <?php |
||
18 | class Builder |
||
19 | { |
||
20 | /** |
||
21 | * @var Restful |
||
22 | */ |
||
23 | protected $model; |
||
24 | |||
25 | /** |
||
26 | * @var Client |
||
27 | */ |
||
28 | protected $client; |
||
29 | |||
30 | /** |
||
31 | * @var Grammar |
||
32 | */ |
||
33 | protected $grammar; |
||
34 | |||
35 | /** |
||
36 | * @var mixed[] |
||
37 | */ |
||
38 | protected $wheres = []; |
||
39 | |||
40 | /** |
||
41 | * @var string[] |
||
42 | */ |
||
43 | private $order; |
||
44 | |||
45 | /** |
||
46 | * @var int |
||
47 | */ |
||
48 | private $limit; |
||
49 | |||
50 | /** |
||
51 | * @var int[] |
||
52 | */ |
||
53 | private $goodStatusCodes = [ |
||
54 | Response::HTTP_OK, |
||
55 | Response::HTTP_CREATED, |
||
56 | Response::HTTP_ACCEPTED |
||
57 | ]; |
||
58 | |||
59 | /** |
||
60 | * Builder constructor. |
||
61 | * @param Client $client |
||
62 | * @param Restful $model |
||
63 | */ |
||
64 | public function __construct(Client $client, Restful $model) |
||
69 | |||
70 | /** |
||
71 | * What model are we querying? |
||
72 | * @param string $class |
||
73 | * @return Builder |
||
74 | */ |
||
75 | public static function model(string $class) |
||
80 | |||
81 | /** |
||
82 | * Get the index route for the model via the options route. |
||
83 | * @param string $route |
||
84 | * @param null $id |
||
85 | * @return Route |
||
86 | * @throws Exceptions\UndefinedIndexException |
||
87 | * @throws RouteNotFoundException |
||
88 | */ |
||
89 | private function getModelRoute(string $route, $id = null): Route |
||
105 | |||
106 | /** |
||
107 | * Get the JSON from the given URL. |
||
108 | * @param Route $route |
||
109 | * @param array $queryString |
||
110 | * @param array $postData |
||
111 | * @return MessageInterface |
||
112 | * @throws Exceptions\UndefinedIndexException |
||
113 | */ |
||
114 | private function getResponse(Route $route, array $queryString = [], array $postData = []): ?MessageInterface |
||
125 | |||
126 | /** |
||
127 | * Extract JSON from a Response. |
||
128 | * @param MessageInterface $response |
||
129 | * @return mixed |
||
130 | * @throws Exceptions\UndefinedIndexException |
||
131 | */ |
||
132 | private function parseJsonFromResponse(MessageInterface $response) |
||
158 | |||
159 | /** |
||
160 | * Is the JSON responses a paginatable one? |
||
161 | * @param mixed[] $json |
||
162 | * @return bool |
||
163 | */ |
||
164 | private function isPaginatedResponse(array $json): bool |
||
168 | |||
169 | /** |
||
170 | * Extract data from the JSON |
||
171 | * @param $json |
||
172 | * @return array |
||
173 | * @throws InvalidArgumentException |
||
174 | */ |
||
175 | private function extractDataFromJson($json): array |
||
183 | |||
184 | /** |
||
185 | * Add a where clause. |
||
186 | * @param string $column |
||
187 | * @param $value |
||
188 | * @return Builder |
||
189 | */ |
||
190 | public function where(string $column, $value): self |
||
200 | |||
201 | /** |
||
202 | * Add a whereIn clause. |
||
203 | * @param string $column |
||
204 | * @param mixed[] $values |
||
205 | * @return Builder |
||
206 | */ |
||
207 | public function whereIn(string $column, array $values): self |
||
217 | |||
218 | /** |
||
219 | * Return all the wheres |
||
220 | * @return mixed[] |
||
221 | */ |
||
222 | public function getWheres(): array |
||
226 | |||
227 | /** |
||
228 | * Set an order |
||
229 | * @param string $column |
||
230 | * @param string $direction |
||
231 | * @return $this\ |
||
232 | */ |
||
233 | public function order(string $column, string $direction): self |
||
242 | |||
243 | /** |
||
244 | * Get the order |
||
245 | * @return array|null |
||
246 | */ |
||
247 | public function getOrder(): ?array |
||
251 | |||
252 | /** |
||
253 | * Specify a limit |
||
254 | * @param int $limit |
||
255 | * @return $this |
||
256 | */ |
||
257 | public function limit(int $limit): self |
||
263 | |||
264 | /** |
||
265 | * Get the limit |
||
266 | * @return int|null |
||
267 | */ |
||
268 | public function getLimit(): ?int |
||
272 | |||
273 | /** |
||
274 | * Call the API, and return the models. |
||
275 | * @return Collection |
||
276 | * @throws Exceptions\UndefinedIndexException |
||
277 | */ |
||
278 | public function get(): Collection |
||
303 | |||
304 | /** |
||
305 | * @param string $route |
||
306 | * @param mixed[] $data |
||
307 | * @param mixed $id |
||
308 | * @return bool |
||
309 | * @throws Exceptions\UndefinedIndexException |
||
310 | */ |
||
311 | private function _call(string $route, array $data, $id = null): bool |
||
321 | |||
322 | /** |
||
323 | * @param mixed[] $data |
||
324 | * @return bool |
||
325 | * @throws Exceptions\UndefinedIndexException |
||
326 | */ |
||
327 | public function insert(array $data): bool |
||
331 | |||
332 | /** |
||
333 | * @param mixed $id |
||
334 | * @param mixed[] $data |
||
335 | * @return bool |
||
336 | * @throws Exceptions\UndefinedIndexException |
||
337 | */ |
||
338 | public function update($id, array $data): bool |
||
342 | |||
343 | /** |
||
344 | * @param mixed $id |
||
345 | * @return bool |
||
346 | * @throws Exceptions\UndefinedIndexException |
||
347 | */ |
||
348 | public function delete($id): bool |
||
352 | } |
||
353 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.