Complex classes like EcommerceController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EcommerceController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class EcommerceController extends adminController { |
||
| 12 | |||
| 13 | public function dashboardAction() { |
||
| 14 | $this->view->setTitle('Онлайн магазин'); |
||
| 15 | $this->view->page(); |
||
| 16 | } |
||
| 17 | |||
| 18 | public function configureAction() { |
||
| 19 | if (!empty($_POST['config'])) { |
||
| 20 | $config = App::$cur->ecommerce->config; |
||
| 21 | $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
||
| 22 | $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
||
| 23 | $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
||
| 24 | $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
||
| 25 | $config['notify_mail'] = $_POST['config']['notify_mail']; |
||
| 26 | $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
||
| 27 | $config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
||
| 28 | $config['orderPrefix'] = $_POST['config']['orderPrefix']; |
||
| 29 | $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
||
| 30 | $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
||
| 31 | $config['filtersInLast'] = empty($_POST['config']['filtersInLast']) ? false : true; |
||
| 32 | $config['defaultNeedDelivery'] = empty($_POST['config']['defaultNeedDelivery']) ? false : true; |
||
| 33 | Config::save('module', $config, 'Ecommerce'); |
||
| 34 | Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
||
| 35 | } |
||
| 36 | $managers = [ |
||
| 37 | 'Ecommerce\Delivery', |
||
| 38 | 'Ecommerce\PayType', |
||
| 39 | 'Ecommerce\Warehouse', |
||
| 40 | 'Ecommerce\Unit', |
||
| 41 | 'Ecommerce\Card', |
||
| 42 | 'Ecommerce\Discount', |
||
| 43 | 'Ecommerce\Cart\Stage', |
||
| 44 | 'Ecommerce\Item\Type', |
||
| 45 | 'Ecommerce\Item\Option', |
||
| 46 | 'Ecommerce\Item\Offer\Option', |
||
| 47 | 'Ecommerce\Item\Offer\Price\Type', |
||
| 48 | 'Ecommerce\UserAdds\Field', |
||
| 49 | 'Ecommerce\Cart\Status', |
||
| 50 | 'Ecommerce\Delivery\Field', |
||
| 51 | 'Ecommerce\Delivery\Provider', |
||
| 52 | ]; |
||
| 53 | $this->view->setTitle('Настройки магазина'); |
||
| 54 | $this->view->page(['data' => compact('managers')]); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function reBlockIndexAction() { |
||
| 65 | |||
| 66 | public function reSearchIndexAction($i = 0) { |
||
| 83 | |||
| 84 | public function newOrdersSubscribeAction() { |
||
| 87 | |||
| 88 | public function closeCartAction($cartId = 0) { |
||
| 101 | |||
| 102 | } |