Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 30 | class MailService |
||
|
|
|||
| 31 | { |
||
| 32 | /** @var \Eccube\Application */ |
||
| 33 | public $app; |
||
| 34 | |||
| 35 | |||
| 36 | /** @var \Eccube\Entity\BaseInfo */ |
||
| 37 | public $BaseInfo; |
||
| 38 | |||
| 39 | 51 | public function __construct(Application $app) |
|
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * Send customer confirm mail. |
||
| 48 | * |
||
| 49 | * @param $Customer 会員情報 |
||
| 50 | * @param $activateUrl アクティベート用url |
||
| 51 | */ |
||
| 52 | 3 | public function sendCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
|
| 53 | { |
||
| 54 | |||
| 55 | 3 | log_info('仮会員登録メール送信開始'); |
|
| 56 | |||
| 57 | 3 | $body = $this->app->renderView('Mail/entry_confirm.twig', array( |
|
| 58 | 3 | 'Customer' => $Customer, |
|
| 59 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 60 | 3 | 'activateUrl' => $activateUrl, |
|
| 61 | )); |
||
| 62 | |||
| 63 | 3 | $message = \Swift_Message::newInstance() |
|
| 64 | 3 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録のご確認') |
|
| 65 | 3 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
|
| 66 | 3 | ->setTo(array($Customer->getEmail())) |
|
| 67 | 3 | ->setBcc($this->BaseInfo->getEmail01()) |
|
| 68 | 3 | ->setReplyTo($this->BaseInfo->getEmail03()) |
|
| 69 | 3 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
| 70 | 3 | ->setBody($body); |
|
| 71 | |||
| 72 | 3 | $event = new EventArgs( |
|
| 73 | array( |
||
| 74 | 3 | 'message' => $message, |
|
| 75 | 3 | 'Customer' => $Customer, |
|
| 76 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 77 | 3 | 'activateUrl' => $activateUrl, |
|
| 78 | ), |
||
| 79 | 3 | null |
|
| 80 | ); |
||
| 81 | 3 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_CONFIRM, $event); |
|
| 82 | |||
| 83 | 3 | $count = $this->app->mail($message, $failures); |
|
| 84 | |||
| 85 | 3 | log_info('仮会員登録メール送信完了', array('count' => $count)); |
|
| 86 | |||
| 87 | 3 | return $count; |
|
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Send customer complete mail. |
||
| 92 | * |
||
| 93 | * @param $Customer 会員情報 |
||
| 94 | */ |
||
| 95 | 3 | View Code Duplication | public function sendCustomerCompleteMail(\Eccube\Entity\Customer $Customer) |
| 96 | { |
||
| 97 | 3 | log_info('会員登録完了メール送信開始'); |
|
| 98 | |||
| 99 | 3 | $body = $this->app->renderView('Mail/entry_complete.twig', array( |
|
| 100 | 3 | 'Customer' => $Customer, |
|
| 101 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 102 | )); |
||
| 103 | |||
| 104 | 3 | $message = \Swift_Message::newInstance() |
|
| 105 | 3 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録が完了しました。') |
|
| 106 | 3 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
|
| 107 | 3 | ->setTo(array($Customer->getEmail())) |
|
| 108 | 3 | ->setBcc($this->BaseInfo->getEmail01()) |
|
| 109 | 3 | ->setReplyTo($this->BaseInfo->getEmail03()) |
|
| 110 | 3 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
| 111 | 3 | ->setBody($body); |
|
| 112 | |||
| 113 | 3 | $event = new EventArgs( |
|
| 114 | array( |
||
| 115 | 3 | 'message' => $message, |
|
| 116 | 3 | 'Customer' => $Customer, |
|
| 117 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 118 | ), |
||
| 119 | 3 | null |
|
| 120 | ); |
||
| 121 | 3 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_COMPLETE, $event); |
|
| 122 | |||
| 123 | 3 | $count = $this->app->mail($message); |
|
| 124 | |||
| 125 | 3 | log_info('会員登録完了メール送信完了', array('count' => $count)); |
|
| 126 | |||
| 127 | 3 | return $count; |
|
| 128 | } |
||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * Send withdraw mail. |
||
| 133 | * |
||
| 134 | * @param $Customer 会員情報 |
||
| 135 | * @param $email 会員email |
||
| 136 | */ |
||
| 137 | 3 | View Code Duplication | public function sendCustomerWithdrawMail(\Eccube\Entity\Customer $Customer, $email) |
| 138 | { |
||
| 139 | 3 | log_info('退会手続き完了メール送信開始'); |
|
| 140 | |||
| 141 | 3 | $body = $this->app->renderView('Mail/customer_withdraw_mail.twig', array( |
|
| 142 | 3 | 'Customer' => $Customer, |
|
| 143 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 144 | )); |
||
| 145 | |||
| 146 | 3 | $message = \Swift_Message::newInstance() |
|
| 147 | 3 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 退会手続きのご完了') |
|
| 148 | 3 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
|
| 149 | 3 | ->setTo(array($email)) |
|
| 150 | 3 | ->setBcc($this->BaseInfo->getEmail01()) |
|
| 151 | 3 | ->setReplyTo($this->BaseInfo->getEmail03()) |
|
| 152 | 3 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
| 153 | 3 | ->setBody($body); |
|
| 154 | |||
| 155 | 3 | $event = new EventArgs( |
|
| 156 | array( |
||
| 157 | 3 | 'message' => $message, |
|
| 158 | 3 | 'Customer' => $Customer, |
|
| 159 | 3 | 'BaseInfo' => $this->BaseInfo, |
|
| 160 | 3 | 'email' => $email, |
|
| 161 | ), |
||
| 162 | 3 | null |
|
| 163 | ); |
||
| 164 | 3 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_WITHDRAW, $event); |
|
| 165 | |||
| 166 | 3 | $count = $this->app->mail($message); |
|
| 167 | |||
| 168 | 3 | log_info('退会手続き完了メール送信完了', array('count' => $count)); |
|
| 169 | |||
| 170 | 3 | return $count; |
|
| 171 | } |
||
| 172 | |||
| 173 | |||
| 174 | /** |
||
| 175 | * Send contact mail. |
||
| 176 | * |
||
| 177 | * @param $formData お問い合わせ内容 |
||
| 178 | */ |
||
| 179 | 6 | View Code Duplication | public function sendContactMail($formData) |
| 180 | { |
||
| 181 | 6 | log_info('お問い合わせ受付メール送信開始'); |
|
| 182 | |||
| 183 | 6 | $body = $this->app->renderView('Mail/contact_mail.twig', array( |
|
| 184 | 6 | 'data' => $formData, |
|
| 185 | 6 | 'BaseInfo' => $this->BaseInfo, |
|
| 186 | )); |
||
| 187 | |||
| 188 | // 問い合わせ者にメール送信 |
||
| 189 | 6 | $message = \Swift_Message::newInstance() |
|
| 190 | 6 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] お問い合わせを受け付けました。') |
|
| 191 | 6 | ->setFrom(array($this->BaseInfo->getEmail02() => $this->BaseInfo->getShopName())) |
|
| 192 | 6 | ->setTo(array($formData['email'])) |
|
| 193 | 6 | ->setBcc($this->BaseInfo->getEmail02()) |
|
| 194 | 6 | ->setReplyTo($this->BaseInfo->getEmail02()) |
|
| 195 | 6 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
| 196 | 6 | ->setBody($body); |
|
| 197 | |||
| 198 | 6 | $event = new EventArgs( |
|
| 199 | array( |
||
| 200 | 6 | 'message' => $message, |
|
| 201 | 6 | 'formData' => $formData, |
|
| 202 | 6 | 'BaseInfo' => $this->BaseInfo, |
|
| 203 | ), |
||
| 204 | 6 | null |
|
| 205 | ); |
||
| 206 | 6 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CONTACT, $event); |
|
| 207 | |||
| 208 | 6 | $count = $this->app->mail($message); |
|
| 209 | |||
| 210 | 6 | log_info('お問い合わせ受付メール送信完了', array('count' => $count)); |
|
| 211 | |||
| 212 | 6 | return $count; |
|
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Alias of sendContactMail(). |
||
| 217 | * |
||
| 218 | * @param $formData お問い合わせ内容 |
||
| 219 | * @see sendContactMail() |
||
| 220 | * @deprecated since 3.0.0, to be removed in 3.1 |
||
| 221 | * @link https://github.com/EC-CUBE/ec-cube/issues/1315 |
||
| 222 | */ |
||
| 223 | public function sendrContactMail($formData) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Send order mail. |
||
| 230 | * |
||
| 231 | * @param \Eccube\Entity\Order $Order 受注情報 |
||
| 232 | * @return string |
||
| 233 | */ |
||
| 234 | 24 | public function sendOrderMail(\Eccube\Entity\Order $Order) |
|
| 273 | |||
| 274 | |||
| 275 | /** |
||
| 276 | * Send admin customer confirm mail. |
||
| 277 | * |
||
| 278 | * @param $Customer 会員情報 |
||
| 279 | * @param $activateUrl アクティベート用url |
||
| 280 | */ |
||
| 281 | 3 | View Code Duplication | public function sendAdminCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
| 316 | |||
| 317 | |||
| 318 | /** |
||
| 319 | * Send admin order mail. |
||
| 320 | * |
||
| 321 | * @param $Order 受注情報 |
||
| 322 | * @param $formData 入力内容 |
||
| 323 | */ |
||
| 324 | 5 | public function sendAdminOrderMail(\Eccube\Entity\Order $Order, $formData) |
|
| 360 | |||
| 361 | /** |
||
| 362 | * Send password reset notification mail. |
||
| 363 | * |
||
| 364 | * @param $Customer 会員情報 |
||
| 365 | */ |
||
| 366 | 3 | View Code Duplication | public function sendPasswordResetNotificationMail(\Eccube\Entity\Customer $Customer, $reset_url) |
| 401 | |||
| 402 | /** |
||
| 403 | * Send password reset notification mail. |
||
| 404 | * |
||
| 405 | * @param $Customer 会員情報 |
||
| 406 | */ |
||
| 407 | 3 | View Code Duplication | public function sendPasswordResetCompleteMail(\Eccube\Entity\Customer $Customer, $password) |
| 442 | |||
| 443 | } |
||
| 444 |