| Conditions | 13 |
| Paths | 52 |
| Total Lines | 103 |
| Code Lines | 65 |
| Lines | 29 |
| Ratio | 28.16 % |
| Tests | 17 |
| CRAP Score | 21.5881 |
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 |
||
| 37 | 4 | public function index(Application $app, Request $request, $page_no = null) |
|
| 38 | { |
||
| 39 | |||
| 40 | $session = $request->getSession(); |
||
| 41 | |||
| 42 | $searchForm = $app['form.factory'] |
||
| 43 | ->createBuilder('admin_search_order') |
||
| 44 | ->getForm(); |
||
| 45 | |||
| 46 | 4 | $pagination = array(); |
|
| 47 | |||
| 48 | $disps = $app['eccube.repository.master.disp']->findAll(); |
||
| 49 | $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
||
| 50 | $page_count = $app['config']['default_page_count']; |
||
| 51 | 4 | $page_status = null; |
|
| 52 | 4 | $active = false; |
|
| 53 | |||
| 54 | if ('POST' === $request->getMethod()) { |
||
| 55 | |||
| 56 | $searchForm->handleRequest($request); |
||
| 57 | |||
| 58 | View Code Duplication | if ($searchForm->isValid()) { |
|
| 59 | $searchData = $searchForm->getData(); |
||
| 60 | |||
| 61 | // paginator |
||
| 62 | $qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
||
| 63 | 4 | $page_no = 1; |
|
| 64 | $pagination = $app['paginator']()->paginate( |
||
| 65 | $qb, |
||
| 66 | $page_no, |
||
| 67 | $page_count |
||
| 68 | ); |
||
| 69 | |||
| 70 | // sessionのデータ保持 |
||
| 71 | $session->set('eccube.admin.order.search', $searchData); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | if (is_null($page_no)) { |
||
| 75 | // sessionを削除 |
||
| 76 | $session->remove('eccube.admin.order.search'); |
||
| 77 | } else { |
||
| 78 | // pagingなどの処理 |
||
| 79 | $searchData = $session->get('eccube.admin.order.search'); |
||
| 80 | if (!is_null($searchData)) { |
||
| 81 | |||
| 82 | // 公開ステータス |
||
| 83 | $status = $request->get('status'); |
||
| 84 | 1 | if (!empty($status)) { |
|
| 85 | if ($status != $app['config']['admin_product_stock_status']) { |
||
| 86 | $searchData['status']->clear(); |
||
| 87 | $searchData['status']->add($status); |
||
| 88 | } else { |
||
| 89 | $searchData['stock_status'] = $app['config']['disabled']; |
||
| 90 | } |
||
| 91 | $page_status = $status; |
||
| 92 | } |
||
| 93 | // 表示件数 |
||
| 94 | $pcount = $request->get('page_count'); |
||
| 95 | |||
| 96 | 1 | $page_count = empty($pcount) ? $page_count : $pcount; |
|
| 97 | |||
| 98 | $qb = $app['eccube.repository.order']->getQueryBuilderBySearchDataForAdmin($searchData); |
||
| 99 | $pagination = $app['paginator']()->paginate( |
||
| 100 | $qb, |
||
| 101 | $page_no, |
||
| 102 | $page_count |
||
| 103 | ); |
||
| 104 | |||
| 105 | // セッションから検索条件を復元 |
||
| 106 | 1 | if (!empty($searchData['status'])) { |
|
| 107 | $searchData['status'] = $app['eccube.repository.master.order_status']->find($searchData['status']); |
||
| 108 | } |
||
| 109 | View Code Duplication | if (count($searchData['sex']) > 0) { |
|
| 110 | 1 | $sex_ids = array(); |
|
| 111 | 1 | foreach ($searchData['sex'] as $Sex) { |
|
| 112 | $sex_ids[] = $Sex->getId(); |
||
| 113 | } |
||
| 114 | $searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids)); |
||
| 115 | } |
||
| 116 | View Code Duplication | if (count($searchData['payment']) > 0) { |
|
| 117 | 1 | $payment_ids = array(); |
|
| 118 | 1 | foreach ($searchData['payment'] as $Payment) { |
|
| 119 | $payment_ids[] = $Payment->getId(); |
||
| 120 | } |
||
| 121 | $searchData['payment'] = $app['eccube.repository.payment']->findBy(array('id' => $payment_ids)); |
||
| 122 | } |
||
| 123 | $searchForm->setData($searchData); |
||
| 124 | } |
||
| 125 | 1 | } |
|
| 126 | 4 | } |
|
| 127 | |||
| 128 | 4 | return $app->render('Order/index.twig', array( |
|
| 129 | 4 | 'searchForm' => $searchForm->createView(), |
|
| 130 | 'pagination' => $pagination, |
||
| 131 | 'disps' => $disps, |
||
| 132 | 'pageMaxis' => $pageMaxis, |
||
| 133 | 'page_no' => $page_no, |
||
| 134 | 'page_status' => $page_status, |
||
| 135 | 'page_count' => $page_count, |
||
| 136 | 'active' => $active, |
||
| 137 | )); |
||
| 138 | |||
| 139 | 4 | } |
|
| 140 | |||
| 316 |