1 | <?php |
||
20 | class Builder |
||
21 | { |
||
22 | /** |
||
23 | * @var Restful |
||
24 | */ |
||
25 | protected $model; |
||
26 | |||
27 | /** |
||
28 | * @var Client |
||
29 | */ |
||
30 | protected $client; |
||
31 | |||
32 | /** |
||
33 | * @var Grammar |
||
34 | */ |
||
35 | protected $grammar; |
||
36 | |||
37 | /** |
||
38 | * @var mixed[] |
||
39 | */ |
||
40 | protected $wheres = []; |
||
41 | |||
42 | /** |
||
43 | * @var string[] |
||
44 | */ |
||
45 | private $order; |
||
46 | |||
47 | /** |
||
48 | * @var int |
||
49 | */ |
||
50 | private $limit; |
||
51 | |||
52 | /** |
||
53 | * @var int[] |
||
54 | */ |
||
55 | private $goodStatusCodes = [ |
||
56 | Response::HTTP_OK, |
||
57 | Response::HTTP_CREATED, |
||
58 | Response::HTTP_ACCEPTED |
||
59 | ]; |
||
60 | /** |
||
61 | * @var LoggerInterface |
||
62 | */ |
||
63 | private $logger; |
||
64 | |||
65 | /** |
||
66 | * Builder constructor. |
||
67 | * @param Client $client |
||
68 | * @param LoggerInterface $logger |
||
69 | * @param Restful $model |
||
70 | */ |
||
71 | public function __construct(Client $client, LoggerInterface $logger, Restful $model) |
||
77 | |||
78 | /** |
||
79 | * What model are we querying? |
||
80 | * @param string $class |
||
81 | * @return Builder |
||
82 | */ |
||
83 | public static function model(string $class) |
||
88 | |||
89 | private function newModelInstance(): Model |
||
93 | |||
94 | /** |
||
95 | * Get the index route for the model via the options route. |
||
96 | * @param string $route |
||
97 | * @param null $id |
||
98 | * @return Route |
||
99 | * @throws Exceptions\UndefinedIndexException |
||
100 | * @throws RouteNotFoundException |
||
101 | */ |
||
102 | private function getModelRoute(string $route, $id = null): Route |
||
117 | |||
118 | /** |
||
119 | * Get the JSON from the given URL. |
||
120 | * @param Route $route |
||
121 | * @param array $queryString |
||
122 | * @param array $postData |
||
123 | * @return MessageInterface |
||
124 | * @throws Exceptions\UndefinedIndexException |
||
125 | */ |
||
126 | private function getResponse(Route $route, array $queryString = [], array $postData = []): ?MessageInterface |
||
149 | |||
150 | /** |
||
151 | * Extract JSON from a Response. |
||
152 | * @param MessageInterface $response |
||
153 | * @return mixed |
||
154 | * @throws Exceptions\UndefinedIndexException |
||
155 | */ |
||
156 | private function parseJsonFromResponse(MessageInterface $response) |
||
182 | |||
183 | /** |
||
184 | * Is the JSON responses a paginatable one? |
||
185 | * @param mixed[] $json |
||
186 | * @return bool |
||
187 | */ |
||
188 | private function isPaginatedResponse(array $json): bool |
||
192 | |||
193 | /** |
||
194 | * Extract data from the JSON |
||
195 | * @param $json |
||
196 | * @return array |
||
197 | * @throws InvalidArgumentException |
||
198 | */ |
||
199 | private function extractDataFromJson($json): array |
||
207 | |||
208 | /** |
||
209 | * Add a where clause. |
||
210 | * @param string $column |
||
211 | * @param $value |
||
212 | * @return Builder |
||
213 | */ |
||
214 | public function where(string $column, $value): self |
||
224 | |||
225 | /** |
||
226 | * Add a whereIn clause. |
||
227 | * @param string $column |
||
228 | * @param mixed[] $values |
||
229 | * @return Builder |
||
230 | */ |
||
231 | public function whereIn(string $column, array $values): self |
||
241 | |||
242 | /** |
||
243 | * Return all the wheres |
||
244 | * @return mixed[] |
||
245 | */ |
||
246 | public function getWheres(): array |
||
250 | |||
251 | /** |
||
252 | * Set an order |
||
253 | * @param string $column |
||
254 | * @param string $direction |
||
255 | * @return $this\ |
||
256 | */ |
||
257 | public function order(string $column, string $direction): self |
||
266 | |||
267 | /** |
||
268 | * Get the order |
||
269 | * @return array|null |
||
270 | */ |
||
271 | public function getOrder(): ?array |
||
275 | |||
276 | /** |
||
277 | * Specify a limit |
||
278 | * @param int $limit |
||
279 | * @return $this |
||
280 | */ |
||
281 | public function limit(int $limit): self |
||
287 | |||
288 | /** |
||
289 | * Get the limit |
||
290 | * @return int|null |
||
291 | */ |
||
292 | public function getLimit(): ?int |
||
296 | |||
297 | /** |
||
298 | * Call the API, and return the models. |
||
299 | * @return Collection |
||
300 | * @throws Exceptions\UndefinedIndexException |
||
301 | */ |
||
302 | public function get(): Collection |
||
334 | |||
335 | /** |
||
336 | * @param string $route |
||
337 | * @param mixed[] $data |
||
338 | * @param mixed $id |
||
339 | * @return bool |
||
340 | * @throws Exceptions\UndefinedIndexException |
||
341 | */ |
||
342 | private function _call(string $route, array $data, $id = null): bool |
||
352 | |||
353 | /** |
||
354 | * @param mixed[] $data |
||
355 | * @return bool |
||
356 | * @throws Exceptions\UndefinedIndexException |
||
357 | */ |
||
358 | public function insert(array $data): bool |
||
362 | |||
363 | /** |
||
364 | * @param mixed $id |
||
365 | * @param mixed[] $data |
||
366 | * @return bool |
||
367 | * @throws Exceptions\UndefinedIndexException |
||
368 | */ |
||
369 | public function update($id, array $data): bool |
||
373 | |||
374 | /** |
||
375 | * @param mixed $id |
||
376 | * @return bool |
||
377 | * @throws Exceptions\UndefinedIndexException |
||
378 | */ |
||
379 | public function delete($id): bool |
||
383 | |||
384 | /** |
||
385 | * Should we log requests? |
||
386 | * @return bool |
||
387 | */ |
||
388 | private function shouldLog(): bool |
||
392 | } |
||
393 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.