| Conditions | 17 |
| Paths | 197 |
| Total Lines | 145 |
| Code Lines | 93 |
| Lines | 145 |
| Ratio | 100 % |
| 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 |
||
| 42 | View Code Duplication | public function index(Application $app, Request $request, $page_no = null) |
|
| 43 | { |
||
| 44 | $session = $request->getSession(); |
||
| 45 | |||
| 46 | $builder = $app['form.factory'] |
||
| 47 | ->createBuilder(SearchOrderType::class); |
||
| 48 | |||
| 49 | $event = new EventArgs( |
||
| 50 | array( |
||
| 51 | 'builder' => $builder, |
||
| 52 | ), |
||
| 53 | $request |
||
| 54 | ); |
||
| 55 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event); |
||
| 56 | |||
| 57 | $searchForm = $builder->getForm(); |
||
| 58 | |||
| 59 | $pagination = array(); |
||
| 60 | |||
| 61 | $disps = $app['eccube.repository.master.disp']->findAll(); |
||
| 62 | $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
||
| 63 | $page_count = $app['config']['default_page_count']; |
||
| 64 | $page_status = null; |
||
| 65 | $active = false; |
||
| 66 | |||
| 67 | if ('POST' === $request->getMethod()) { |
||
| 68 | |||
| 69 | $searchForm->handleRequest($request); |
||
| 70 | |||
| 71 | if ($searchForm->isValid()) { |
||
| 72 | $searchData = $searchForm->getData(); |
||
| 73 | |||
| 74 | // paginator |
||
| 75 | $qb = $app['eccube.repository.shipping']->getQueryBuilderBySearchDataForAdmin($searchData); |
||
| 76 | |||
| 77 | $event = new EventArgs( |
||
| 78 | array( |
||
| 79 | 'form' => $searchForm, |
||
| 80 | 'qb' => $qb, |
||
| 81 | ), |
||
| 82 | $request |
||
| 83 | ); |
||
| 84 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
||
| 85 | |||
| 86 | $page_no = 1; |
||
| 87 | $pagination = $app['paginator']()->paginate( |
||
| 88 | $qb, |
||
| 89 | $page_no, |
||
| 90 | $page_count |
||
| 91 | ); |
||
| 92 | |||
| 93 | // sessionのデータ保持 |
||
| 94 | $session->set('eccube.admin.shipping.search', $searchData); |
||
| 95 | $session->set('eccube.admin.shipping.search.page_no', $page_no); |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | if (is_null($page_no) && $request->get('resume') != Constant::ENABLED) { |
||
| 99 | // sessionを削除 |
||
| 100 | $session->remove('eccube.admin.shipping.search'); |
||
| 101 | $session->remove('eccube.admin.shipping.search.page_no'); |
||
| 102 | } else { |
||
| 103 | // pagingなどの処理 |
||
| 104 | $searchData = $session->get('eccube.admin.shipping.search'); |
||
| 105 | if (is_null($page_no)) { |
||
| 106 | $page_no = intval($session->get('eccube.admin.shipping.search.page_no')); |
||
| 107 | } else { |
||
| 108 | $session->set('eccube.admin.shipping.search.page_no', $page_no); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (!is_null($searchData)) { |
||
| 112 | |||
| 113 | // 公開ステータス |
||
| 114 | $status = $request->get('status'); |
||
| 115 | if (!empty($status)) { |
||
| 116 | if ($status != $app['config']['admin_product_stock_status']) { |
||
| 117 | $searchData['status']->clear(); |
||
| 118 | $searchData['status']->add($status); |
||
| 119 | } else { |
||
| 120 | $searchData['stock_status'] = $app['config']['disabled']; |
||
| 121 | } |
||
| 122 | $page_status = $status; |
||
| 123 | } |
||
| 124 | // 表示件数 |
||
| 125 | $pcount = $request->get('page_count'); |
||
| 126 | |||
| 127 | $page_count = empty($pcount) ? $page_count : $pcount; |
||
| 128 | |||
| 129 | $qb = $app['eccube.repository.shipping']->getQueryBuilderBySearchDataForAdmin($searchData); |
||
| 130 | |||
| 131 | $event = new EventArgs( |
||
| 132 | array( |
||
| 133 | 'form' => $searchForm, |
||
| 134 | 'qb' => $qb, |
||
| 135 | ), |
||
| 136 | $request |
||
| 137 | ); |
||
| 138 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event); |
||
| 139 | |||
| 140 | $pagination = $app['paginator']()->paginate( |
||
| 141 | $qb, |
||
| 142 | $page_no, |
||
| 143 | $page_count |
||
| 144 | ); |
||
| 145 | |||
| 146 | // セッションから検索条件を復元 |
||
| 147 | if (!empty($searchData['status'])) { |
||
| 148 | $searchData['status'] = $app['eccube.repository.master.order_status']->find($searchData['status']); |
||
| 149 | } |
||
| 150 | if (count($searchData['multi_status']) > 0) { |
||
| 151 | $statusIds = array(); |
||
| 152 | foreach ($searchData['multi_status'] as $Status) { |
||
| 153 | $statusIds[] = $Status->getId(); |
||
| 154 | } |
||
| 155 | $searchData['multi_status'] = $app['eccube.repository.master.order_status']->findBy(array('id' => $statusIds)); |
||
| 156 | } |
||
| 157 | if (count($searchData['sex']) > 0) { |
||
| 158 | $sex_ids = array(); |
||
| 159 | foreach ($searchData['sex'] as $Sex) { |
||
| 160 | $sex_ids[] = $Sex->getId(); |
||
| 161 | } |
||
| 162 | $searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids)); |
||
| 163 | } |
||
| 164 | if (count($searchData['payment']) > 0) { |
||
| 165 | $payment_ids = array(); |
||
| 166 | foreach ($searchData['payment'] as $Payment) { |
||
| 167 | $payment_ids[] = $Payment->getId(); |
||
| 168 | } |
||
| 169 | $searchData['payment'] = $app['eccube.repository.payment']->findBy(array('id' => $payment_ids)); |
||
| 170 | } |
||
| 171 | $searchForm->setData($searchData); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | return [ |
||
| 177 | 'searchForm' => $searchForm->createView(), |
||
| 178 | 'pagination' => $pagination, |
||
| 179 | 'disps' => $disps, |
||
| 180 | 'pageMaxis' => $pageMaxis, |
||
| 181 | 'page_no' => $page_no, |
||
| 182 | 'page_status' => $page_status, |
||
| 183 | 'page_count' => $page_count, |
||
| 184 | 'active' => $active, |
||
| 185 | ]; |
||
| 186 | } |
||
| 187 | } |
||
| 188 |