| Conditions | 8 |
| Paths | 6 |
| Total Lines | 34 |
| Lines | 26 |
| Ratio | 76.47 % |
| Tests | 0 |
| CRAP Score | 72 |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function items(string $table, int $page, int $onPage, array $filter = []): array |
||
| 43 | { |
||
| 44 | $skipped = 0; |
||
| 45 | $offset = ($page - 1) * $onPage; |
||
| 46 | $items = []; |
||
| 47 | $iterator = ''; |
||
| 48 | View Code Duplication | do { |
|
| 49 | $pattern = null; |
||
| 50 | $res = $this->connection->sscan($table, $iterator, $pattern, $onPage * 10); |
||
| 51 | if (!$res) { |
||
| 52 | return $items; |
||
| 53 | } |
||
| 54 | foreach ($res as $member) { |
||
| 55 | $item = [ |
||
| 56 | 'member' => $member, |
||
| 57 | 'length' => strlen($member), |
||
| 58 | ]; |
||
| 59 | if (!Filter::apply($item, $filter)) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | |||
| 63 | if ($skipped < $offset) { |
||
| 64 | $skipped++; |
||
| 65 | continue; |
||
| 66 | } |
||
| 67 | |||
| 68 | $items[$member] = $item; |
||
| 69 | if (count($items) === $onPage) { |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } while ($iterator !== 0 && count($items) < $onPage); |
||
| 74 | return $items; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.