| Conditions | 8 |
| Paths | 9 |
| Total Lines | 78 |
| Code Lines | 48 |
| 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 |
||
| 103 | public function edit(Application $app, Request $request, $id, $did = null) |
||
| 104 | { |
||
| 105 | $Customer = $this->customerRepository->find($id); |
||
| 106 | if (is_null($Customer)) { |
||
| 107 | throw new NotFoundHttpException(); |
||
| 108 | } |
||
| 109 | |||
| 110 | // 配送先住所最大値判定 |
||
| 111 | // $idが存在する際は、追加処理ではなく、編集の処理ため本ロジックスキップ |
||
| 112 | if (is_null($did)) { |
||
| 113 | $addressCurrNum = count($Customer->getCustomerAddresses()); |
||
| 114 | $addressMax = $this->appConfig['deliv_addr_max']; |
||
| 115 | if ($addressCurrNum >= $addressMax) { |
||
| 116 | throw new NotFoundHttpException('お届け先の登録数の上限を超えています'); |
||
| 117 | } |
||
| 118 | } else { |
||
| 119 | $CustomerAddress = $this->customerAddressRepository->find($did); |
||
| 120 | if (is_null($CustomerAddress) || $CustomerAddress->getCustomer()->getId() != $Customer->getId()) { |
||
| 121 | throw new NotFoundHttpException(); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | $CustomerAddress = $this->customerAddressRepository->findOrCreateByCustomerAndId($Customer, $did); |
||
| 126 | |||
| 127 | $builder = $this->formFactory |
||
| 128 | ->createBuilder(CustomerAddressType::class, $CustomerAddress); |
||
| 129 | |||
| 130 | $event = new EventArgs( |
||
| 131 | array( |
||
| 132 | 'builder' => $builder, |
||
| 133 | 'Customer' => $Customer, |
||
| 134 | 'CustomerAddress' => $CustomerAddress, |
||
| 135 | ), |
||
| 136 | $request |
||
| 137 | ); |
||
| 138 | |||
| 139 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELIVERY_EDIT_INDEX_INITIALIZE, $event); |
||
| 140 | |||
| 141 | $form = $builder->getForm(); |
||
| 142 | |||
| 143 | if ('POST' === $request->getMethod()) { |
||
| 144 | $form->handleRequest($request); |
||
| 145 | if ($form->isValid()) { |
||
| 146 | log_info('お届け先登録開始', array($did)); |
||
| 147 | |||
| 148 | $this->entityManager->persist($CustomerAddress); |
||
| 149 | $this->entityManager->flush(); |
||
| 150 | |||
| 151 | log_info('お届け先登録完了', array($did)); |
||
| 152 | |||
| 153 | $event = new EventArgs( |
||
| 154 | array( |
||
| 155 | 'form' => $form, |
||
| 156 | 'Customer' => $Customer, |
||
| 157 | 'CustomerAddress' => $CustomerAddress, |
||
| 158 | ), |
||
| 159 | $request |
||
| 160 | ); |
||
| 161 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELIVERY_EDIT_INDEX_COMPLETE, $event); |
||
| 162 | |||
| 163 | $app->addSuccess('admin.customer.delivery.save.complete', 'admin'); |
||
| 164 | |||
| 165 | return $app->redirect($app->url('admin_customer_delivery_edit', array( |
||
| 166 | 'id' => $Customer->getId(), |
||
| 167 | 'did' => $CustomerAddress->getId(), |
||
| 168 | ))); |
||
| 169 | } else { |
||
| 170 | $app->addError('admin.customer.delivery.save.failed', 'admin'); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | return [ |
||
| 175 | 'form' => $form->createView(), |
||
| 176 | 'Customer' => $Customer, |
||
| 177 | 'CustomerAddress' => $CustomerAddress, |
||
| 178 | ]; |
||
| 179 | |||
| 180 | } |
||
| 181 | |||
| 232 |