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