| Conditions | 12 |
| Paths | 16 |
| Total Lines | 133 |
| 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 |
||
| 77 | public function index(Request $request, Order $Order) |
||
| 78 | { |
||
| 79 | $MailHistories = $this->mailHistoryRepository->findBy(['Order' => $Order]); |
||
| 80 | |||
| 81 | $builder = $this->formFactory->createBuilder(MailType::class); |
||
| 82 | |||
| 83 | $event = new EventArgs( |
||
| 84 | [ |
||
| 85 | 'builder' => $builder, |
||
| 86 | 'Order' => $Order, |
||
| 87 | 'MailHistories' => $MailHistories, |
||
| 88 | ], |
||
| 89 | $request |
||
| 90 | ); |
||
| 91 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_INITIALIZE, $event); |
||
| 92 | |||
| 93 | $form = $builder->getForm(); |
||
| 94 | |||
| 95 | if ('POST' === $request->getMethod()) { |
||
| 96 | $form->handleRequest($request); |
||
| 97 | |||
| 98 | $mode = $request->get('mode'); |
||
| 99 | |||
| 100 | // テンプレート変更の場合は. バリデーション前に内容差し替え. |
||
| 101 | switch ($mode) { |
||
| 102 | case 'change': |
||
| 103 | if ($form->get('template')->isValid()) { |
||
| 104 | /** @var $data \Eccube\Entity\MailTemplate */ |
||
| 105 | $MailTemplate = $form->get('template')->getData(); |
||
| 106 | $data = $form->getData(); |
||
|
|
|||
| 107 | |||
| 108 | $twig = $MailTemplate->getFileName(); |
||
| 109 | if (!$twig) { |
||
| 110 | $twig = 'Mail/order.twig'; |
||
| 111 | } |
||
| 112 | |||
| 113 | // 本文確認用 |
||
| 114 | $body = $this->createBody($Order, $twig); |
||
| 115 | // HTMLテンプレート |
||
| 116 | $htmlBody = null; |
||
| 117 | $targetTwig = explode('.', $twig); |
||
| 118 | $suffix = '.html'; |
||
| 119 | $htmlTwig = $targetTwig[0].$suffix.'.'.$targetTwig[1]; |
||
| 120 | if ($this->twig->getLoader()->exists($htmlTwig)) { |
||
| 121 | $htmlBody = $this->createBody($Order, $htmlTwig); |
||
| 122 | } |
||
| 123 | |||
| 124 | $form = $builder->getForm(); |
||
| 125 | $event = new EventArgs( |
||
| 126 | [ |
||
| 127 | 'form' => $form, |
||
| 128 | 'Order' => $Order, |
||
| 129 | 'MailTemplate' => $MailTemplate, |
||
| 130 | ], |
||
| 131 | $request |
||
| 132 | ); |
||
| 133 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_CHANGE, $event); |
||
| 134 | $form->get('template')->setData($MailTemplate); |
||
| 135 | $form->get('mail_subject')->setData($MailTemplate->getMailSubject()); |
||
| 136 | $form->get('tpl_data')->setData($body); |
||
| 137 | if (!is_null($htmlBody)) { |
||
| 138 | $form->get('html_tpl_data')->setData($htmlBody); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | break; |
||
| 142 | case 'confirm': |
||
| 143 | if ($form->isValid()) { |
||
| 144 | $builder->setAttribute('freeze', true); |
||
| 145 | $builder->setAttribute('freeze_display_text', false); |
||
| 146 | $form = $builder->getForm(); |
||
| 147 | $form->handleRequest($request); |
||
| 148 | |||
| 149 | return $this->render('@admin/Order/mail_confirm.twig', [ |
||
| 150 | 'form' => $form->createView(), |
||
| 151 | 'Order' => $Order, |
||
| 152 | 'MailHistories' => $MailHistories, |
||
| 153 | ]); |
||
| 154 | } |
||
| 155 | break; |
||
| 156 | case 'complete': |
||
| 157 | if ($form->isValid()) { |
||
| 158 | $data = $form->getData(); |
||
| 159 | $data['tpl_data'] = $form->get('tpl_data')->getData(); |
||
| 160 | $data['html_tpl_data'] = $form->get('html_tpl_data')->getData(); |
||
| 161 | |||
| 162 | // メール送信 |
||
| 163 | $message = $this->mailService->sendAdminOrderMail($Order, $data); |
||
| 164 | |||
| 165 | // 送信履歴を保存. |
||
| 166 | $MailTemplate = $form->get('template')->getData(); |
||
| 167 | $MailHistory = new MailHistory(); |
||
| 168 | $MailHistory |
||
| 169 | ->setMailSubject($message->getSubject()) |
||
| 170 | ->setMailBody($message->getBody()) |
||
| 171 | ->setSendDate(new \DateTime()) |
||
| 172 | ->setOrder($Order); |
||
| 173 | |||
| 174 | // HTML用メールの設定 |
||
| 175 | if (!is_null($data['html_tpl_data'])) { |
||
| 176 | $multipart = $message->getChildren(); |
||
| 177 | $MailHistory->setMailHtmlBody($multipart[0]->getBody()); |
||
| 178 | } |
||
| 179 | |||
| 180 | $this->entityManager->persist($MailHistory); |
||
| 181 | $this->entityManager->flush($MailHistory); |
||
| 182 | |||
| 183 | $event = new EventArgs( |
||
| 184 | [ |
||
| 185 | 'form' => $form, |
||
| 186 | 'Order' => $Order, |
||
| 187 | 'MailTemplate' => $MailTemplate, |
||
| 188 | 'MailHistory' => $MailHistory, |
||
| 189 | ], |
||
| 190 | $request |
||
| 191 | ); |
||
| 192 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_COMPLETE, $event); |
||
| 193 | |||
| 194 | $this->addSuccess('admin.order.mail_complete.364', 'admin'); |
||
| 195 | |||
| 196 | return $this->redirectToRoute('admin_order_page', ['page_no' => $this->session->get('eccube.admin.order.search.page_no', 1)]); |
||
| 197 | } |
||
| 198 | break; |
||
| 199 | default: |
||
| 200 | break; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | return [ |
||
| 205 | 'form' => $form->createView(), |
||
| 206 | 'Order' => $Order, |
||
| 207 | 'MailHistories' => $MailHistories, |
||
| 208 | ]; |
||
| 209 | } |
||
| 210 | |||
| 355 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.