| Conditions | 10 |
| Paths | 144 |
| Total Lines | 49 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 56 | public function getAllReports($forums = 0, string $order = 'ASC', int $perpage = 0, int &$start = 0, int $report_result = 0, int $reportId = 0): array |
||
| 57 | { |
||
| 58 | $forumCriteria = ''; |
||
| 59 | $row = []; |
||
| 60 | if ('DESC' === $order) { |
||
| 61 | $operator_for_position = '>'; |
||
| 62 | } else { |
||
| 63 | $order = 'ASC'; |
||
| 64 | $operator_for_position = '<'; |
||
| 65 | } |
||
| 66 | $order_criteria = " ORDER BY r.report_id $order"; |
||
| 67 | |||
| 68 | if ($perpage <= 0) { |
||
| 69 | $perpage = 10; |
||
| 70 | } |
||
| 71 | if (empty($start)) { |
||
| 72 | $start = 0; |
||
| 73 | } |
||
| 74 | $result_criteria = ' AND r.report_result = ' . $report_result; |
||
| 75 | |||
| 76 | if ($forums) { |
||
| 77 | $forumCriteria = ''; |
||
| 78 | } elseif (!\is_array($forums)) { |
||
| 79 | $forums = [$forums]; |
||
| 80 | $forumCriteria = ' AND p.forum_id IN (' . \implode(',', $forums) . ')'; |
||
| 81 | } |
||
| 82 | $tables_criteria = ' FROM ' . $this->db->prefix('newbb_report') . ' r, ' . $this->db->prefix('newbb_posts') . ' p WHERE r.post_id= p.post_id'; |
||
| 83 | |||
| 84 | if ($reportId) { |
||
| 85 | $sql = 'SELECT COUNT(*) as report_count' . $tables_criteria . $forumCriteria . $result_criteria . " AND report_id $operator_for_position $reportId" . $order_criteria; |
||
| 86 | $result = $this->db->query($sql); |
||
| 87 | if ($this->db->isResultSet($result)) { |
||
| 88 | $row = $this->db->fetchArray($result); |
||
| 89 | } |
||
| 90 | $position = $row['report_count'] ?? 0; |
||
| 91 | $start = (int)($position / $perpage) * $perpage; |
||
| 92 | } |
||
| 93 | |||
| 94 | $sql = 'SELECT r.*, p.subject, p.topic_id, p.forum_id' . $tables_criteria . $forumCriteria . $result_criteria . $order_criteria; |
||
| 95 | $result = $this->db->query($sql, $perpage, $start); |
||
| 96 | $ret = []; |
||
| 97 | //$reportHandler = Newbb\Helper::getInstance()->getHandler('Report'); |
||
| 98 | if ($this->db->isResultSet($result)) { |
||
| 99 | while (false !== ($myrow = $this->db->fetchArray($result))) { |
||
| 100 | $ret[] = $myrow; // return as array |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return $ret; |
||
| 105 | } |
||
| 128 |
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.