| Conditions | 17 |
| Paths | 800 |
| Total Lines | 76 |
| Code Lines | 45 |
| 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 |
||
| 108 | public function Addons() |
||
| 109 | { |
||
| 110 | $list = Addon::get(); |
||
| 111 | |||
| 112 | $search = $this->request->getVar('search'); |
||
| 113 | $type = $this->request->getVar('type'); |
||
| 114 | $compat = $this->request->getVar('compatibility'); |
||
| 115 | $tags = $this->request->getVar('tags'); |
||
| 116 | $sort = $this->request->getVar('sort'); |
||
| 117 | $view = $this->request->getVar('view'); |
||
| 118 | |||
| 119 | if (!$view) { |
||
| 120 | $view = 'list'; |
||
| 121 | } |
||
| 122 | |||
| 123 | if (!in_array($sort, array('name', 'downloads', 'newest'))) { |
||
| 124 | $sort = null; |
||
| 125 | } |
||
| 126 | |||
| 127 | // Proxy out a search to elastic if any parameters are set. |
||
| 128 | if ($search || $type || $compat || $tags) { |
||
| 129 | |||
| 130 | $bool = new Query\BoolQuery(); |
||
| 131 | |||
| 132 | $query = new Query(); |
||
| 133 | $query->setQuery($bool); |
||
| 134 | $query->setSize(count($list)); |
||
| 135 | |||
| 136 | |||
| 137 | if ($search) { |
||
| 138 | $match = new Match(); |
||
| 139 | $match->setField('_all', $search); |
||
| 140 | |||
| 141 | $bool->addMust($match); |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($type) { |
||
| 145 | $bool->addMust(new Query\Term(array('type' => $type))); |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($compat) { |
||
| 149 | $bool->addMust(new Query\Terms('compatibility', (array) $compat)); |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($tags) { |
||
| 153 | $bool->addMust(new Query\Terms('tag', (array) $tags)); |
||
| 154 | } |
||
| 155 | |||
| 156 | $list = new ResultList($this->elastica->getIndex(), $query); |
||
| 157 | |||
| 158 | if ($sort) { |
||
| 159 | $ids = $list->column('ID'); |
||
| 160 | |||
| 161 | if ($ids) { |
||
| 162 | $list = Addon::get()->byIDs($ids); |
||
| 163 | } else { |
||
| 164 | $list = new ArrayList(); |
||
| 165 | } |
||
| 166 | } else { |
||
| 167 | $list = $list->toArrayList(); |
||
| 168 | } |
||
| 169 | } else { |
||
| 170 | if (!$sort) $sort = 'downloads'; |
||
| 171 | } |
||
| 172 | |||
| 173 | switch ($sort) { |
||
| 174 | case 'name': $list = $list->sort('Name'); break; |
||
| 175 | case 'newest': $list = $list->sort('Released', 'DESC'); break; |
||
| 176 | case 'downloads': $list = $list->sort('Downloads', 'DESC'); break; |
||
| 177 | } |
||
| 178 | |||
| 179 | $list = new PaginatedList($list, $this->request); |
||
| 180 | $list->setPageLength(16); |
||
| 181 | |||
| 182 | return $list; |
||
| 183 | } |
||
| 184 | |||
| 242 |