Failed Conditions
Push — master ( 36ccc8...f8bd2f )
by Kentaro
34:47
created

MailService   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 372
Duplicated Lines 49.19 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 71.74%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 183
loc 372
ccs 33
cts 46
cp 0.7174
rs 10
c 3
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B sendCustomerConfirmMail() 0 31 1
B sendCustomerCompleteMail() 30 30 1
B sendCustomerWithdrawMail() 31 31 1
B sendContactMail() 31 31 1
A sendrContactMail() 0 4 1
B sendOrderMail() 0 34 1
B sendAdminCustomerConfirmMail() 31 31 1
B sendAdminOrderMail() 0 32 1
B sendPasswordResetNotificationMail() 30 30 1
B sendPasswordResetCompleteMail() 30 30 1

How to fix   Duplicated Code   

Duplicated Code

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
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Service;
25
26
use Eccube\Application;
27
use Eccube\Event\EccubeEvents;
28
use Eccube\Event\EventArgs;
29
30
class MailService
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
31
{
32
    /** @var \Eccube\Application */
33
    public $app;
34
35
36
    /** @var \Eccube\Entity\BaseInfo */
37 24
    public $BaseInfo;
0 ignored issues
show
Coding Style introduced by
Member variable "BaseInfo" is not in valid camel caps format
Loading history...
38
39 24
    public function __construct(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
40
    {
41
        $this->app = $app;
42
        $this->BaseInfo = $app['eccube.repository.base_info']->get();
43
    }
44
45
46
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
introduced by
Doc comment for parameter "$activateUrl" missing
Loading history...
47
     * Send customer confirm mail.
48
     *
49
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
50 2
     * @param $activateUrl アクティベート用url
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
51
     */
52
    public function sendCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl)
53
    {
54
55 2
        $body = $this->app->renderView('Mail/entry_confirm.twig', array(
56
            'Customer' => $Customer,
57
            'BaseInfo' => $this->BaseInfo,
58
            'activateUrl' => $activateUrl,
59 2
        ));
60
61
        $message = \Swift_Message::newInstance()
62
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録のご確認')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
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
                'BaseInfo' => $this->BaseInfo,
75
                'activateUrl' => $activateUrl,
76 2
            ),
77
            null
78
        );
79
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_CONFIRM, $event);
80
81 2
        $this->app->mail($message);
82
    }
83
84 2
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
85
     * Send customer complete mail.
86
     *
87
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
88
     */
89 View Code Duplication
    public function sendCustomerCompleteMail(\Eccube\Entity\Customer $Customer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
    {
91
92
        $body = $this->app->renderView('Mail/entry_complete.twig', array(
93
            'Customer' => $Customer,
94
            'BaseInfo' => $this->BaseInfo,
95
        ));
96
97
        $message = \Swift_Message::newInstance()
98
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録が完了しました。')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
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 2
106
        $event = new EventArgs(
107
            array(
108
                'message' => $message,
109
                'Customer' => $Customer,
110 2
                'BaseInfo' => $this->BaseInfo,
111
            ),
112
            null
113 2
        );
114
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_COMPLETE, $event);
115
116 2
        $this->app->mail($message);
117
118
    }
119
120
121
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$email" missing
Loading history...
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
122
     * Send withdraw mail.
123
     *
124
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
125
     * @param $email 会員email
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
126
     */
127 View Code Duplication
    public function sendCustomerWithdrawMail(\Eccube\Entity\Customer $Customer, $email)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129
130
        $body = $this->app->renderView('Mail/customer_withdraw_mail.twig', array(
131
            'Customer' => $Customer,
132 5
            'BaseInfo' => $this->BaseInfo,
133
        ));
134
135
        $message = \Swift_Message::newInstance()
136
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] 退会手続きのご完了')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
137 5
            ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()))
138
            ->setTo(array($email))
139
            ->setBcc($this->BaseInfo->getEmail01())
140
            ->setReplyTo($this->BaseInfo->getEmail03())
141 5
            ->setReturnPath($this->BaseInfo->getEmail04())
142
            ->setBody($body);
143
144 5
        $event = new EventArgs(
145
            array(
146
                'message' => $message,
147
                'Customer' => $Customer,
148
                'BaseInfo' => $this->BaseInfo,
149
                'email' => $email,
150
            ),
151
            null
152 5
        );
153
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CUSTOMER_WITHDRAW, $event);
154
155
        $this->app->mail($message);
156
157
    }
158
159
160
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$formData" missing
Loading history...
161
     * Send contact mail.
162 1
     *
163
     * @param $formData お問い合わせ内容
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
164
     */
165 1 View Code Duplication
    public function sendContactMail($formData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
166
    {
167
168
        $body = $this->app->renderView('Mail/contact_mail.twig', array(
169
            'data' => $formData,
170
            'BaseInfo' => $this->BaseInfo,
171
        ));
172 5
173
        // 問い合わせ者にメール送信
174
        $message = \Swift_Message::newInstance()
175
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] お問い合わせを受け付けました。')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
176
            ->setFrom(array($this->BaseInfo->getEmail02() => $this->BaseInfo->getShopName()))
177
            ->setTo(array($formData['email']))
178 5
            ->setBcc($this->BaseInfo->getEmail02())
179 5
            ->setReplyTo($this->BaseInfo->getEmail02())
180
            ->setReturnPath($this->BaseInfo->getEmail04())
181
            ->setBody($body);
182
183 5
        $event = new EventArgs(
184
            array(
185
                'message' => $message,
186
                'formData' => $formData,
187
                'BaseInfo' => $this->BaseInfo,
188
            ),
189
            null
190
        );
191
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_CONTACT, $event);
192
193
        $this->app->mail($message);
194
195
    }
196
197
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$formData" missing
Loading history...
198
     * Alias of sendContactMail().
199
     *
200
     * @param $formData お問い合わせ内容
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
201
     * @see sendContactMail()
202
     * @deprecated since 3.0.0, to be removed in 3.1
203 2
     * @link https://github.com/EC-CUBE/ec-cube/issues/1315
204
     */
205
    public function sendrContactMail($formData)
206
    {
207
        $this->sendContactMail($formData);
208
    }
209
210
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Order" missing
Loading history...
211 2
     * Send order mail.
212
     *
213
     * @param $Order 受注情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
214
     */
215
    public function sendOrderMail(\Eccube\Entity\Order $Order)
216
    {
217
218
        $MailTemplate = $this->app['eccube.repository.mail_template']->find(1);
219
220
        $body = $this->app->renderView($MailTemplate->getFileName(), array(
221
            'header' => $MailTemplate->getHeader(),
222
            'footer' => $MailTemplate->getFooter(),
223
            'Order' => $Order,
224
        ));
225
226
        $message = \Swift_Message::newInstance()
227
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] ' . $MailTemplate->getSubject())
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
228
            ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()))
229
            ->setTo(array($Order->getEmail()))
230
            ->setBcc($this->BaseInfo->getEmail01())
231 2
            ->setReplyTo($this->BaseInfo->getEmail03())
232
            ->setReturnPath($this->BaseInfo->getEmail04())
233
            ->setBody($body);
234
235 2
        $event = new EventArgs(
236 2
            array(
237
                'message' => $message,
238
                'Order' => $Order,
239
                'MailTemplate' => $MailTemplate,
240 2
                'BaseInfo' => $this->BaseInfo,
241
            ),
242
            null
243
        );
244
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_ORDER, $event);
245
246
        $this->app->mail($message);
247
248
    }
249
250
251
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
introduced by
Doc comment for parameter "$activateUrl" missing
Loading history...
252
     * Send admin customer confirm mail.
253
     *
254
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
255
     * @param $activateUrl アクティベート用url
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
256
     */
257 View Code Duplication
    public function sendAdminCustomerConfirmMail(\Eccube\Entity\Customer $Customer, $activateUrl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258 2
    {
259
260
        $body = $this->app->renderView('Mail/entry_confirm.twig', array(
261
            'Customer' => $Customer,
262
            'activateUrl' => $activateUrl,
263
        ));
264
265 2
        $message = \Swift_Message::newInstance()
266
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] 会員登録のご確認')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
267
            ->setFrom(array($this->BaseInfo->getEmail03() => $this->BaseInfo->getShopName()))
268
            ->setTo(array($Customer->getEmail()))
269
            ->setBcc($this->BaseInfo->getEmail01())
270
            ->setReplyTo($this->BaseInfo->getEmail03())
271
            ->setReturnPath($this->BaseInfo->getEmail04())
272
            ->setBody($body);
273
274
        $event = new EventArgs(
275
            array(
276
                'message' => $message,
277
                'Customer' => $Customer,
278
                'BaseInfo' => $this->BaseInfo,
279
                'activateUrl' => $activateUrl,
280
            ),
281
            null
282
        );
283 2
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_ADMIN_CUSTOMER_CONFIRM, $event);
284
285
        $this->app->mail($message);
286
287
    }
288
289
290 2
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Order" missing
Loading history...
introduced by
Doc comment for parameter "$formData" missing
Loading history...
291
     * Send admin order mail.
292
     *
293
     * @param $Order 受注情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
294
     * @param $formData 入力内容
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
295
     */
296
    public function sendAdminOrderMail(\Eccube\Entity\Order $Order, $formData)
297
    {
298
299
        $body = $this->app->renderView('Mail/order.twig', array(
300
            'header' => $formData['header'],
301
            'footer' => $formData['footer'],
302
            'Order' => $Order,
303
        ));
304
305
        $message = \Swift_Message::newInstance()
306
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] ' . $formData['subject'])
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
307
            ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()))
308
            ->setTo(array($Order->getEmail()))
309
            ->setBcc($this->BaseInfo->getEmail01())
310
            ->setReplyTo($this->BaseInfo->getEmail03())
311
            ->setReturnPath($this->BaseInfo->getEmail04())
312
            ->setBody($body);
313
314
        $event = new EventArgs(
315
            array(
316
                'message' => $message,
317
                'Order' => $Order,
318
                'formData' => $formData,
319
                'BaseInfo' => $this->BaseInfo,
320
            ),
321
            null
322
        );
323
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_ADMIN_ORDER, $event);
324
325
        $this->app->mail($message);
326
327
    }
328
329
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$reset_url" missing
Loading history...
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
330
     * Send password reset notification mail.
331
     *
332
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
333
     */
334 View Code Duplication
    public function sendPasswordResetNotificationMail(\Eccube\Entity\Customer $Customer, $reset_url)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
335
    {
336
        $body = $this->app->renderView('Mail/forgot_mail.twig', array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
337
            'Customer' => $Customer,
338
            'reset_url' => $reset_url
339
        ));
340
341
        $message = \Swift_Message::newInstance()
342
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] パスワード変更のご確認')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
343
            ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()))
344
            ->setTo(array($Customer->getEmail()))
345
            ->setBcc($this->BaseInfo->getEmail01())
346
            ->setReplyTo($this->BaseInfo->getEmail03())
347
            ->setReturnPath($this->BaseInfo->getEmail04())
348
            ->setBody($body);
349
350
        $event = new EventArgs(
351
            array(
352
                'message' => $message,
353
                'Customer' => $Customer,
354
                'BaseInfo' => $this->BaseInfo,
355
                'resetUrl' => $reset_url,
356
            ),
357
            null
358
        );
359
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_PASSWORD_RESET, $event);
360
361
        $this->app->mail($message);
362
363
    }
364
365
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$password" missing
Loading history...
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
366
     * Send password reset notification mail.
367
     *
368
     * @param $Customer 会員情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
369
     */
370 View Code Duplication
    public function sendPasswordResetCompleteMail(\Eccube\Entity\Customer $Customer, $password)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
    {
372
        $body = $this->app->renderView('Mail/reset_complete_mail.twig', array(
373
            'Customer' => $Customer,
374
            'password' => $password,
375
        ));
376
377
        $message = \Swift_Message::newInstance()
378
            ->setSubject('[' . $this->BaseInfo->getShopName() . '] パスワード変更のお知らせ')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
379
            ->setFrom(array($this->BaseInfo->getEmail01() => $this->BaseInfo->getShopName()))
380
            ->setTo(array($Customer->getEmail()))
381
            ->setBcc($this->BaseInfo->getEmail01())
382
            ->setReplyTo($this->BaseInfo->getEmail03())
383
            ->setReturnPath($this->BaseInfo->getEmail04())
384
            ->setBody($body);
385
386
        $event = new EventArgs(
387
            array(
388
                'message' => $message,
389
                'Customer' => $Customer,
390
                'BaseInfo' => $this->BaseInfo,
391
                'password' => $password,
392
            ),
393
            null
394
        );
395
        $this->app['eccube.event.dispatcher']->dispatch(EccubeEvents::MAIL_PASSWORD_RESET_COMPLETE, $event);
396
397
        $this->app->mail($message);
398
399
    }
400
401
}
402