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 | 24 | public function __construct(Application $app) |
|
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * Send customer confirm mail. |
||
| 48 | * |
||
| 49 | * @param $Customer 会員情報 |
||
| 50 | * @param $activateUrl アクティベート用url |
||
| 51 | */ |
||
| 52 | 2 | public function sendCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
|
| 53 | { |
||
| 54 | |||
| 55 | $body = $this->app->renderView('Mail/entry_confirm.twig', array( |
||
| 56 | 'Customer' => $Customer, |
||
| 57 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 58 | 'activateUrl' => $activateUrl, |
||
| 59 | )); |
||
| 60 | |||
| 61 | 2 | $message = \Swift_Message::newInstance() |
|
| 62 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録のご確認') |
||
| 63 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
| 64 | ->setTo(array($Customer->getEmail())) |
||
| 65 | ->setBcc($this->BaseInfo->getEmail01()) |
||
| 66 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
| 67 | ->setReturnPath($this->BaseInfo->getEmail04()) |
||
| 68 | ->setBody($body); |
||
| 69 | |||
| 70 | $event = new EventArgs( |
||
| 71 | array( |
||
| 72 | 'message' => $message, |
||
| 73 | 'Customer' => $Customer, |
||
| 74 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 75 | 'activateUrl' => $activateUrl, |
||
| 76 | ), |
||
| 77 | 2 | null |
|
| 78 | ); |
||
| 79 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_CONFIRM, $event); |
||
| 80 | |||
| 81 | $this->app->mail($message); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Send customer complete mail. |
||
| 86 | * |
||
| 87 | * @param $Customer 会員情報 |
||
| 88 | */ |
||
| 89 | 2 | View Code Duplication | public function sendCustomerCompleteMail(\Eccube\Entity\Customer $Customer) |
| 90 | { |
||
| 91 | |||
| 92 | $body = $this->app->renderView('Mail/entry_complete.twig', array( |
||
| 93 | 'Customer' => $Customer, |
||
| 94 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 95 | )); |
||
| 96 | |||
| 97 | 2 | $message = \Swift_Message::newInstance() |
|
| 98 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録が完了しました。') |
||
| 99 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
| 100 | ->setTo(array($Customer->getEmail())) |
||
| 101 | ->setBcc($this->BaseInfo->getEmail01()) |
||
| 102 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
| 103 | ->setReturnPath($this->BaseInfo->getEmail04()) |
||
| 104 | ->setBody($body); |
||
| 105 | |||
| 106 | $event = new EventArgs( |
||
| 107 | array( |
||
| 108 | 'message' => $message, |
||
| 109 | 'Customer' => $Customer, |
||
| 110 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 111 | ), |
||
| 112 | 2 | null |
|
| 113 | ); |
||
| 114 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_COMPLETE, $event); |
||
| 115 | |||
| 116 | $this->app->mail($message); |
||
| 117 | |||
| 118 | } |
||
| 119 | |||
| 120 | |||
| 121 | /** |
||
| 122 | * Send withdraw mail. |
||
| 123 | * |
||
| 124 | * @param $Customer 会員情報 |
||
| 125 | * @param $email 会員email |
||
| 126 | */ |
||
| 127 | 2 | View Code Duplication | public function sendCustomerWithdrawMail(\Eccube\Entity\Customer $Customer, $email) |
| 128 | { |
||
| 129 | |||
| 130 | $body = $this->app->renderView('Mail/customer_withdraw_mail.twig', array( |
||
| 131 | 'Customer' => $Customer, |
||
| 132 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 133 | )); |
||
| 134 | |||
| 135 | 2 | $message = \Swift_Message::newInstance() |
|
| 136 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 退会手続きのご完了') |
||
| 137 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
| 138 | 2 | ->setTo(array($email)) |
|
| 139 | ->setBcc($this->BaseInfo->getEmail01()) |
||
| 140 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
| 141 | ->setReturnPath($this->BaseInfo->getEmail04()) |
||
| 142 | ->setBody($body); |
||
| 143 | |||
| 144 | $event = new EventArgs( |
||
| 145 | array( |
||
| 146 | 'message' => $message, |
||
| 147 | 'Customer' => $Customer, |
||
| 148 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
| 149 | 'email' => $email, |
||
| 150 | ), |
||
| 151 | 2 | null |
|
| 152 | ); |
||
| 153 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_WITHDRAW, $event); |
||
| 154 | |||
| 155 | $this->app->mail($message); |
||
| 156 | |||
| 157 | } |
||
| 158 | |||
| 159 | |||
| 160 | /** |
||
| 161 | * Send contact mail. |
||
| 162 | * |
||
| 163 | * @param $formData お問い合わせ内容 |
||
| 164 | */ |
||
| 165 | 5 | View Code Duplication | public function sendContactMail($formData) |
| 196 | |||
| 197 | /** |
||
| 198 | * Alias of sendContactMail(). |
||
| 199 | * |
||
| 200 | * @param $formData お問い合わせ内容 |
||
| 201 | * @see sendContactMail() |
||
| 202 | * @deprecated since 3.0.0, to be removed in 3.1 |
||
| 203 | * @link https://github.com/EC-CUBE/ec-cube/issues/1315 |
||
| 204 | */ |
||
| 205 | 1 | public function sendrContactMail($formData) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Send order mail. |
||
| 212 | * |
||
| 213 | * @param $Order 受注情報 |
||
| 214 | */ |
||
| 215 | 5 | public function sendOrderMail(\Eccube\Entity\Order $Order) |
|
| 249 | |||
| 250 | |||
| 251 | /** |
||
| 252 | * Send admin customer confirm mail. |
||
| 253 | * |
||
| 254 | * @param $Customer 会員情報 |
||
| 255 | * @param $activateUrl アクティベート用url |
||
| 256 | */ |
||
| 257 | 2 | View Code Duplication | public function sendAdminCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
| 288 | |||
| 289 | |||
| 290 | /** |
||
| 291 | * Send admin order mail. |
||
| 292 | * |
||
| 293 | * @param $Order 受注情報 |
||
| 294 | * @param $formData 入力内容 |
||
| 295 | */ |
||
| 296 | 2 | public function sendAdminOrderMail(\Eccube\Entity\Order $Order, $formData) |
|
| 328 | |||
| 329 | /** |
||
| 330 | * Send password reset notification mail. |
||
| 331 | * |
||
| 332 | * @param $Customer 会員情報 |
||
| 333 | */ |
||
| 334 | 2 | View Code Duplication | public function sendPasswordResetNotificationMail(\Eccube\Entity\Customer $Customer, $reset_url) |
| 364 | |||
| 365 | /** |
||
| 366 | * Send password reset notification mail. |
||
| 367 | * |
||
| 368 | * @param $Customer 会員情報 |
||
| 369 | */ |
||
| 370 | 2 | View Code Duplication | public function sendPasswordResetCompleteMail(\Eccube\Entity\Customer $Customer, $password) |
| 400 | |||
| 401 | } |
||
| 402 |