Conditions | 5 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function getAll(Client $client, QueryAllRequestInterface $request) |
||
17 | { |
||
18 | $lastId = null; |
||
19 | $data = ['results' => []]; |
||
20 | do { |
||
21 | $request->sort('id')->limit(static::DEFAULT_PAGE_SIZE)->withTotal(false); |
||
22 | if ($lastId != null) { |
||
23 | $request->where('id > "' . $lastId . '"'); |
||
24 | } |
||
25 | $response = $client->execute($request); |
||
26 | if ($response->isError() || is_null($response->toObject())) { |
||
27 | break; |
||
28 | } |
||
29 | $results = $response->toArray()['results']; |
||
30 | $data['results'] = array_merge($data['results'], $results); |
||
31 | $lastId = end($results)['id']; |
||
32 | } while (count($results) >= static::DEFAULT_PAGE_SIZE); |
||
33 | |||
34 | $result = $request->mapResult($data, $client->getConfig()->getContext()); |
||
35 | |||
36 | return $result; |
||
37 | } |
||
38 | } |
||
39 |