Conditions | 6 |
Paths | 5 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
1 | <?php |
||
30 | public function filter(ArrayIterator $collection): ArrayIterator |
||
31 | { |
||
32 | $results = new ArrayIterator(); |
||
33 | $collection->rewind(); |
||
34 | |||
35 | $totalRecords = $collection->count(); |
||
36 | $resultsOffset = ($this->page * $this->numPerPage) - $this->numPerPage; |
||
37 | $resultsEndOffset = $resultsOffset + $this->numPerPage; |
||
38 | |||
39 | if ($resultsOffset > $totalRecords) { |
||
40 | throw new LogicException('There aren\'t that many pages for this result set.'); |
||
41 | } |
||
42 | |||
43 | for ($x = 0; $x < $totalRecords; $x ++) { |
||
44 | if ($collection->valid()) { |
||
45 | $row = $collection->current(); |
||
46 | if ($x >= $resultsOffset && $x <= $resultsEndOffset) { |
||
47 | $results->append($row); |
||
48 | } |
||
49 | $collection->next(); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | return $results; |
||
54 | } |
||
55 | |||
91 | } |