Conditions | 7 |
Paths | 16 |
Total Lines | 35 |
Lines | 20 |
Ratio | 57.14 % |
Changes | 0 |
1 | <?php |
||
12 | public function sanitize() |
||
13 | { |
||
14 | |||
15 | // TODO: Move to some config file |
||
16 | $maxResultsPerRequest = 1000; |
||
17 | $maxPaginationDepth = 10000; |
||
18 | |||
19 | $input = $this->all(); |
||
20 | |||
21 | View Code Duplication | if ($this->has('offset')) { |
|
22 | $input['offset'] = intval($input['offset']); |
||
23 | if ($input['offset'] < 0) { |
||
24 | unset($input['offset']); |
||
25 | $this->warnings[] = 'Offset cannot be negative.'; |
||
26 | } elseif ($input['offset'] > $maxPaginationDepth) { |
||
27 | $input['offset'] = $maxPaginationDepth; |
||
28 | $this->warnings[] = 'Pagination depth is limited to ' . $maxPaginationDepth . ' results.'; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | View Code Duplication | if ($this->has('limit')) { |
|
33 | $input['limit'] = intval($input['limit']); |
||
34 | if ($input['limit'] < 1) { |
||
35 | unset($input['limit']); |
||
36 | $this->warnings[] = 'Limit cannot be negative.'; |
||
37 | } elseif ($input['limit'] > $maxResultsPerRequest) { |
||
38 | $input['limit'] = $maxResultsPerRequest; |
||
39 | $this->warnings[] = 'Limiting to max ' . $maxResultsPerRequest . ' results per request.'; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | $this->replace($input); |
||
44 | |||
45 | return $this->all(); |
||
46 | } |
||
47 | |||
68 |