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 | 24 | public $BaseInfo; |
|
38 | |||
39 | 24 | public function __construct(Application $app) |
|
44 | |||
45 | |||
46 | /** |
||
47 | * Send customer confirm mail. |
||
48 | * |
||
49 | * @param $Customer 会員情報 |
||
50 | 2 | * @param $activateUrl アクティベート用url |
|
51 | */ |
||
52 | public function sendCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl) |
||
53 | { |
||
54 | |||
55 | 2 | log_info('仮会員登録メール送信開始'); |
|
56 | |||
57 | $body = $this->app->renderView('Mail/entry_confirm.twig', array( |
||
58 | 'Customer' => $Customer, |
||
59 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
60 | 'activateUrl' => $activateUrl, |
||
61 | )); |
||
62 | |||
63 | $message = \Swift_Message::newInstance() |
||
64 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録のご確認') |
||
65 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
66 | ->setTo(array($Customer->getEmail())) |
||
67 | ->setBcc($this->BaseInfo->getEmail01()) |
||
68 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
69 | ->setReturnPath($this->BaseInfo->getEmail04()) |
||
70 | ->setBody($body); |
||
71 | |||
72 | $event = new EventArgs( |
||
73 | array( |
||
74 | 'message' => $message, |
||
75 | 'Customer' => $Customer, |
||
76 | 2 | 'BaseInfo' => $this->BaseInfo, |
|
77 | 'activateUrl' => $activateUrl, |
||
78 | ), |
||
79 | null |
||
80 | ); |
||
81 | 2 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_CONFIRM, $event); |
|
82 | |||
83 | $count = $this->app->mail($message, $failures); |
||
84 | 2 | ||
85 | log_info('仮会員登録メール送信完了', array('count' => $count)); |
||
86 | |||
87 | return $count; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Send customer complete mail. |
||
92 | * |
||
93 | * @param $Customer 会員情報 |
||
94 | */ |
||
95 | View Code Duplication | public function sendCustomerCompleteMail(\Eccube\Entity\Customer $Customer) |
|
96 | { |
||
97 | log_info('会員登録完了メール送信開始'); |
||
98 | |||
99 | $body = $this->app->renderView('Mail/entry_complete.twig', array( |
||
100 | 'Customer' => $Customer, |
||
101 | 'BaseInfo' => $this->BaseInfo, |
||
102 | )); |
||
103 | |||
104 | $message = \Swift_Message::newInstance() |
||
105 | 2 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録が完了しました。') |
|
106 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
107 | ->setTo(array($Customer->getEmail())) |
||
108 | ->setBcc($this->BaseInfo->getEmail01()) |
||
109 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
110 | 2 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
111 | ->setBody($body); |
||
112 | |||
113 | 2 | $event = new EventArgs( |
|
114 | array( |
||
115 | 'message' => $message, |
||
116 | 2 | 'Customer' => $Customer, |
|
117 | 'BaseInfo' => $this->BaseInfo, |
||
118 | ), |
||
119 | null |
||
120 | ); |
||
121 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_COMPLETE, $event); |
||
122 | |||
123 | $count = $this->app->mail($message); |
||
124 | |||
125 | log_info('会員登録完了メール送信完了', array('count' => $count)); |
||
126 | |||
127 | return $count; |
||
128 | } |
||
129 | |||
130 | |||
131 | /** |
||
132 | 5 | * Send withdraw mail. |
|
133 | * |
||
134 | * @param $Customer 会員情報 |
||
135 | * @param $email 会員email |
||
136 | */ |
||
137 | 5 | View Code Duplication | public function sendCustomerWithdrawMail(\Eccube\Entity\Customer $Customer, $email) |
138 | { |
||
139 | log_info('退会手続き完了メール送信開始'); |
||
140 | |||
141 | 5 | $body = $this->app->renderView('Mail/customer_withdraw_mail.twig', array( |
|
142 | 'Customer' => $Customer, |
||
143 | 'BaseInfo' => $this->BaseInfo, |
||
144 | 5 | )); |
|
145 | |||
146 | $message = \Swift_Message::newInstance() |
||
147 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] 退会手続きのご完了') |
||
148 | ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName())) |
||
149 | ->setTo(array($email)) |
||
150 | ->setBcc($this->BaseInfo->getEmail01()) |
||
151 | ->setReplyTo($this->BaseInfo->getEmail03()) |
||
152 | 5 | ->setReturnPath($this->BaseInfo->getEmail04()) |
|
153 | ->setBody($body); |
||
154 | |||
155 | $event = new EventArgs( |
||
156 | array( |
||
157 | 'message' => $message, |
||
158 | 'Customer' => $Customer, |
||
159 | 'BaseInfo' => $this->BaseInfo, |
||
160 | 'email' => $email, |
||
161 | ), |
||
162 | 1 | null |
|
163 | ); |
||
164 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_WITHDRAW, $event); |
||
165 | 1 | ||
166 | $count = $this->app->mail($message); |
||
167 | |||
168 | log_info('退会手続き完了メール送信完了', array('count' => $count)); |
||
169 | |||
170 | return $count; |
||
171 | } |
||
172 | 5 | ||
173 | |||
174 | /** |
||
175 | * Send contact mail. |
||
176 | * |
||
177 | * @param $formData お問い合わせ内容 |
||
178 | 5 | */ |
|
179 | 5 | View Code Duplication | public function sendContactMail($formData) |
180 | { |
||
181 | log_info('お問い合わせ受付メール送信開始'); |
||
182 | |||
183 | 5 | $body = $this->app->renderView('Mail/contact_mail.twig', array( |
|
184 | 'data' => $formData, |
||
185 | 'BaseInfo' => $this->BaseInfo, |
||
186 | )); |
||
187 | |||
188 | // 問い合わせ者にメール送信 |
||
189 | $message = \Swift_Message::newInstance() |
||
190 | ->setSubject('[' . $this->BaseInfo->getShopName() . '] お問い合わせを受け付けました。') |
||
191 | ->setFrom(array($this->BaseInfo->getEmail02() => $this->BaseInfo->getShopName())) |
||
192 | ->setTo(array($formData['email'])) |
||
193 | ->setBcc($this->BaseInfo->getEmail02()) |
||
194 | ->setReplyTo($this->BaseInfo->getEmail02()) |
||
195 | ->setReturnPath($this->BaseInfo->getEmail04()) |
||
196 | ->setBody($body); |
||
197 | |||
198 | $event = new EventArgs( |
||
199 | array( |
||
200 | 'message' => $message, |
||
201 | 'formData' => $formData, |
||
202 | 'BaseInfo' => $this->BaseInfo, |
||
203 | 2 | ), |
|
204 | null |
||
205 | ); |
||
206 | $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CONTACT, $event); |
||
207 | |||
208 | $count = $this->app->mail($message); |
||
209 | |||
210 | log_info('お問い合わせ受付メール送信完了', array('count' => $count)); |
||
211 | 2 | ||
212 | 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 | 2 | * @param \Eccube\Entity\Order $Order 受注情報 |
|
232 | * @return string |
||
233 | */ |
||
234 | 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 | 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 | public function sendAdminOrderMail(\Eccube\Entity\Order $Order, $formData) |
||
360 | |||
361 | /** |
||
362 | * Send password reset notification mail. |
||
363 | * |
||
364 | * @param $Customer 会員情報 |
||
365 | */ |
||
366 | public function sendPasswordResetNotificationMail(\Eccube\Entity\Customer $Customer, $reset_url) |
||
400 | |||
401 | /** |
||
402 | * Send password reset notification mail. |
||
403 | * |
||
404 | * @param $Customer 会員情報 |
||
405 | */ |
||
406 | View Code Duplication | public function sendPasswordResetCompleteMail(\Eccube\Entity\Customer $Customer, $password) |
|
440 | |||
441 | } |
||
442 |