| Conditions | 10 |
| Paths | 48 |
| Total Lines | 43 |
| Code Lines | 34 |
| 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 |
||
| 106 | public function &getAllFiles($itemid = 0, $status = -1, $limit = 0, $start = 0, $sort = 'datesub', $order = 'DESC', $category = []): array |
||
| 107 | { |
||
| 108 | $this->table_link = $this->db2->prefix('publisher_items'); |
||
| 109 | $this->field_object = 'itemid'; |
||
| 110 | $this->field_link = 'itemid'; |
||
| 111 | $hasStatusCriteria = false; |
||
| 112 | $criteriaStatus = new CriteriaCompo(); |
||
| 113 | if (\is_array($status)) { |
||
| 114 | $hasStatusCriteria = true; |
||
| 115 | foreach ($status as $v) { |
||
| 116 | $criteriaStatus->add(new Criteria('o.status', $v), 'OR'); |
||
| 117 | } |
||
| 118 | } elseif (-1 != $status) { |
||
| 119 | $hasStatusCriteria = true; |
||
| 120 | $criteriaStatus->add(new Criteria('o.status', $status), 'OR'); |
||
| 121 | } |
||
| 122 | $hasCategoryCriteria = false; |
||
| 123 | $criteriaCategory = new CriteriaCompo(); |
||
| 124 | $category = (array)$category; |
||
| 125 | if (\count($category) > 0 && 0 != $category[0]) { |
||
| 126 | $hasCategoryCriteria = true; |
||
| 127 | foreach ($category as $cat) { |
||
| 128 | $criteriaCategory->add(new Criteria('l.categoryid', $cat), 'OR'); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | $criteriaItemid = new Criteria('o.itemid', $itemid); |
||
| 132 | $criteria = new CriteriaCompo(); |
||
| 133 | if (0 != $itemid) { |
||
| 134 | $criteria->add($criteriaItemid); |
||
| 135 | } |
||
| 136 | if ($hasStatusCriteria) { |
||
| 137 | $criteria->add($criteriaStatus); |
||
| 138 | } |
||
| 139 | if ($hasCategoryCriteria) { |
||
| 140 | $criteria->add($criteriaCategory); |
||
| 141 | } |
||
| 142 | $criteria->setSort($sort); |
||
| 143 | $criteria->setOrder($order); |
||
| 144 | $criteria->setLimit($limit); |
||
| 145 | $criteria->setStart($start); |
||
| 146 | $files = $this->getByLink($criteria, ['o.*'], true); |
||
| 147 | |||
| 148 | return $files; |
||
| 149 | } |
||
| 151 |