| Conditions | 6 |
| Paths | 5 |
| Total Lines | 24 |
| Lines | 9 |
| Ratio | 37.5 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function itemsCount(string $table, array $filter): int |
||
| 18 | { |
||
| 19 | if (!$filter) { |
||
|
|
|||
| 20 | return $this->connection->scard($table); |
||
| 21 | } |
||
| 22 | $iterator = ''; |
||
| 23 | $totalItems = 0; |
||
| 24 | do { |
||
| 25 | $res = $this->connection->sscan($table, $iterator, null, 1000); |
||
| 26 | if (!$res) { |
||
| 27 | return $totalItems; |
||
| 28 | } |
||
| 29 | View Code Duplication | foreach ($res as $member) { |
|
| 30 | $item = [ |
||
| 31 | 'member' => $member, |
||
| 32 | 'length' => strlen($member), |
||
| 33 | ]; |
||
| 34 | if (Filter::apply($item, $filter)) { |
||
| 35 | $totalItems++; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } while ($iterator !== 0); |
||
| 39 | return $totalItems; |
||
| 40 | } |
||
| 41 | |||
| 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.