Conditions | 8 |
Paths | 6 |
Total Lines | 30 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 8 |
Changes | 0 |
1 | <?php |
||
20 | 2 | public function filter(ArrayIterator $collection): ArrayIterator |
|
21 | { |
||
22 | // If pagination wasnt set, dont use it! |
||
23 | 2 | if (!$this->page || !$this->numPerPage) { |
|
24 | 1 | return $collection; |
|
25 | } |
||
26 | |||
27 | 1 | $results = new ArrayIterator(); |
|
28 | 1 | $collection->rewind(); |
|
29 | |||
30 | 1 | $totalRecords = $collection->count(); |
|
31 | 1 | $resultsOffset = ($this->page * $this->numPerPage) - $this->numPerPage; |
|
32 | 1 | $resultsEndOffset = $resultsOffset + $this->numPerPage; |
|
33 | |||
34 | 1 | if ($resultsOffset > $totalRecords) { |
|
35 | 1 | throw new LogicException('There aren\'t that many pages for this result set.'); |
|
36 | } |
||
37 | |||
38 | 1 | for ($x = 0; $x < $totalRecords; $x ++) { |
|
39 | 1 | if ($collection->valid()) { |
|
40 | 1 | $row = $collection->current(); |
|
41 | 1 | if ($x >= $resultsOffset && $x < $resultsEndOffset) { |
|
42 | 1 | $results->append($row); |
|
43 | } |
||
44 | 1 | $collection->next(); |
|
45 | } |
||
46 | } |
||
47 | |||
48 | 1 | return $results; |
|
49 | } |
||
50 | |||
86 | } |