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