Conditions | 38 |
Paths | > 20000 |
Total Lines | 150 |
Code Lines | 104 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 2 | 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 |
||
130 | public function itemListAction($category_id = 0) { |
||
131 | //search |
||
132 | if (!empty($_GET['search'])) { |
||
133 | if (!empty($_GET['inCatalog'])) { |
||
134 | $category_id = (int) $_GET['inCatalog']; |
||
135 | } |
||
136 | $search = $_GET['search']; |
||
137 | } else { |
||
138 | $search = ''; |
||
139 | } |
||
140 | |||
141 | //sort |
||
142 | if (!empty($_GET['sort'])) { |
||
143 | $sort = $_GET['sort']; |
||
144 | } elseif (!empty($this->ecommerce->config['defaultSort'])) { |
||
145 | $sort = $this->ecommerce->config['defaultSort']; |
||
146 | } else { |
||
147 | $sort = ['name' => 'asc']; |
||
148 | } |
||
149 | |||
150 | //category |
||
151 | $category = null; |
||
152 | $categoryClass = 'Ecommerce\Category'; |
||
153 | if (!empty($this->module->config['catalogReplace'])) { |
||
154 | $categoryClass = 'Ecommerce\Catalog'; |
||
155 | } |
||
156 | if ($category_id) { |
||
157 | |||
158 | if (is_numeric($category_id)) { |
||
159 | $category = $categoryClass::get((int) $category_id); |
||
160 | } |
||
161 | if (!$category) { |
||
162 | $category = $categoryClass::get((int) $category_id, 'alias'); |
||
163 | } |
||
164 | if ($category) { |
||
165 | $category_id = $category->id; |
||
166 | } else { |
||
167 | $category_id = 0; |
||
168 | } |
||
169 | |||
170 | } else { |
||
171 | $category_id = 0; |
||
172 | } |
||
173 | if ($category) { |
||
174 | $category->views++; |
||
175 | $category->save(); |
||
176 | } |
||
177 | $active = $category_id; |
||
178 | if (!empty($_GET['categorys'])) { |
||
179 | $categorysList = $_GET['categorys']; |
||
180 | } elseif ($categoryClass === 'Ecommerce\Catalog' && $category) { |
||
181 | $categorysList = array_keys($category->categories(['key' => 'category_id'])); |
||
182 | } else { |
||
183 | $categorysList = $category_id; |
||
184 | } |
||
185 | |||
186 | //items pages |
||
187 | $pages = new \Ui\Pages($_GET, ['count' => $this->ecommerce->getItemsCount([ |
||
188 | 'parent' => $categorysList, |
||
189 | 'search' => trim($search), |
||
190 | 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : [] |
||
191 | ]), |
||
192 | 'limit' => !empty($this->Ecommerce->config['default_limit']) ? $this->Ecommerce->config['default_limit'] : 18, |
||
193 | ]); |
||
194 | if (!empty(App::$cur->ecommerce->config['list_all']) && !empty($_GET['limit']) && $_GET['limit'] == 'all') { |
||
195 | $pages->params['start'] = 0; |
||
196 | $pages->params['limit'] = 0; |
||
197 | $pages->params['pages'] = 1; |
||
198 | } |
||
199 | |||
200 | //bread |
||
201 | $bread = []; |
||
202 | if (!$category || !$category->name) { |
||
203 | if (!empty($_GET['filters']['best'])) { |
||
204 | $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce'); |
||
205 | $bread[] = array('text' => 'Рекомендумые товары'); |
||
206 | } else { |
||
207 | $bread[] = array('text' => 'Каталог'); |
||
208 | } |
||
209 | $this->view->setTitle('Каталог'); |
||
210 | } else { |
||
211 | $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce'); |
||
212 | $categoryIds = array_values(array_filter(explode('/', $category->tree_path))); |
||
213 | foreach ($categoryIds as $id) { |
||
214 | $cat = Ecommerce\Category::get($id); |
||
215 | $bread[] = array('text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id); |
||
216 | } |
||
217 | $bread[] = array('text' => $category->name); |
||
218 | $this->view->setTitle($category->name); |
||
219 | } |
||
220 | |||
221 | //items |
||
222 | $items = $this->ecommerce->getItems([ |
||
223 | 'parent' => $categorysList, |
||
224 | 'start' => $pages->params['start'], |
||
225 | 'count' => $pages->params['limit'], |
||
226 | 'search' => trim($search), |
||
227 | 'sort' => $sort, |
||
228 | 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : [] |
||
229 | ]); |
||
230 | |||
231 | //params |
||
232 | if (!empty(App::$cur->ecommerce->config['filtersByRel'])) { |
||
233 | $categorysList = is_array($categorysList) ? $categorysList : explode(',', $categorysList); |
||
234 | $categorysList = array_filter($categorysList); |
||
235 | $opts = []; |
||
236 | foreach ($categorysList as $categoryId) { |
||
237 | $cat = \Ecommerce\Category::get($categoryId); |
||
238 | if ($cat) { |
||
239 | $opts = array_merge($opts, array_keys($cat->options(['key' => 'item_option_id']))); |
||
240 | } |
||
241 | } |
||
242 | $opts = array_unique($opts); |
||
243 | if ($opts) { |
||
244 | $options = \Ecommerce\Item\Option::getList(['where' => [['item_option_searchable', 1], ['id', $opts, 'IN']], 'order' => ['weight', 'asc']]); |
||
245 | } else { |
||
246 | $options = []; |
||
247 | } |
||
248 | } elseif (empty(App::$cur->ecommerce->config['filtersInLast'])) { |
||
249 | $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1], 'order' => ['weight', 'asc']]); |
||
250 | } else { |
||
251 | $params = $this->ecommerce->getItemsParams([ |
||
252 | 'parent' => $categorysList, |
||
253 | 'search' => trim($search), |
||
254 | 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : [] |
||
255 | ]); |
||
256 | $ids = []; |
||
257 | foreach ($params as $param) { |
||
258 | $ids[] = $param->item_option_id; |
||
259 | } |
||
260 | if ($ids) { |
||
261 | $options = \Ecommerce\Item\Option::getList(['where' => ['id', $ids, 'IN'], 'order' => ['weight', 'asc']]); |
||
262 | } else { |
||
263 | $options = []; |
||
264 | } |
||
265 | } |
||
266 | |||
267 | |||
268 | //child categorys |
||
269 | if ($category) { |
||
270 | $categorys = $category->catalogs; |
||
271 | } else { |
||
272 | $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]); |
||
273 | } |
||
274 | |||
275 | //view content |
||
276 | $this->view->page([ |
||
277 | 'page' => $category ? $category->resolveTemplate() : (!empty(App::$cur->ecommerce->config['defaultCategoryTemplate']) ? App::$cur->ecommerce->config['defaultCategoryTemplate'] : 'current'), |
||
278 | 'content' => $category ? $category->resolveViewer() : (!empty(App::$cur->ecommerce->config['defaultCategoryView']) ? App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'), |
||
279 | 'data' => compact('active', 'category', 'sort', 'search', 'pages', 'items', 'categorys', 'bread', 'options')]); |
||
280 | } |
||
407 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths