| Conditions | 12 |
| Paths | 49 |
| Total Lines | 51 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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); |
||
| 112 | public function getAllFiles($itemId = 0, $status = -1, $limit = 0, $start = 0, $sort = 'datesub', $order = 'DESC', $category = []) |
||
| 113 | { |
||
| 114 | $files = []; |
||
| 115 | |||
| 116 | $this->table_link = $this->db->prefix($this->helper->getDirname() . '_items'); |
||
| 117 | |||
| 118 | $result = $GLOBALS['xoopsDB']->query('SELECT COUNT(*) FROM ' . $this->db->prefix($this->helper->getDirname() . '_files')); |
||
| 119 | [$count] = $GLOBALS['xoopsDB']->fetchRow($result); |
||
| 120 | if ($count > 0) { |
||
| 121 | $this->field_object = 'itemid'; |
||
| 122 | $this->field_link = 'itemid'; |
||
| 123 | $hasStatusCriteria = false; |
||
| 124 | $criteriaStatus = new \CriteriaCompo(); |
||
| 125 | if (\is_array($status)) { |
||
| 126 | $hasStatusCriteria = true; |
||
| 127 | foreach ($status as $v) { |
||
| 128 | $criteriaStatus->add(new \Criteria('o.status', $v), 'OR'); |
||
| 129 | } |
||
| 130 | } elseif (-1 != $status) { |
||
| 131 | $hasStatusCriteria = true; |
||
| 132 | $criteriaStatus->add(new \Criteria('o.status', $status), 'OR'); |
||
| 133 | } |
||
| 134 | $hasCategoryCriteria = false; |
||
| 135 | $criteriaCategory = new \CriteriaCompo(); |
||
| 136 | $category = (array)$category; |
||
| 137 | if (isset($category[0]) && 0 != $category[0] && \count($category) > 0) { |
||
| 138 | $hasCategoryCriteria = true; |
||
| 139 | foreach ($category as $cat) { |
||
| 140 | $criteriaCategory->add(new \Criteria('l.categoryid', $cat), 'OR'); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | $criteriaItemid = new \Criteria('o.itemid', $itemId); |
||
| 144 | $criteria = new \CriteriaCompo(); |
||
| 145 | if (0 != $itemId) { |
||
| 146 | $criteria->add($criteriaItemid); |
||
| 147 | } |
||
| 148 | if ($hasStatusCriteria) { |
||
| 149 | $criteria->add($criteriaStatus); |
||
| 150 | } |
||
| 151 | if ($hasCategoryCriteria) { |
||
| 152 | $criteria->add($criteriaCategory); |
||
| 153 | } |
||
| 154 | $criteria->setSort($sort); |
||
| 155 | $criteria->order = $order; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method |
||
| 156 | $criteria->setLimit($limit); |
||
| 157 | $criteria->setStart($start); |
||
| 158 | $files = $this->getByLink($criteria, ['o.*'], true); |
||
| 159 | // return $files; |
||
| 160 | } |
||
| 161 | |||
| 162 | return $files; |
||
| 163 | } |
||
| 165 |