WithdrawController::index()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 65
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 35
nc 4
nop 2
dl 0
loc 65
ccs 31
cts 31
cp 1
crap 5
rs 8.6195
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

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
25
namespace Eccube\Controller\Mypage;
26
27
use Eccube\Application;
28
use Eccube\Common\Constant;
29
use Eccube\Controller\AbstractController;
30
use Eccube\Event\EccubeEvents;
31
use Eccube\Event\EventArgs;
32
use Eccube\Util\Str;
33
use Symfony\Component\HttpFoundation\Request;
34
35
class WithdrawController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
36
{
37
    /**
38
     * 退会画面.
39
     *
40
     * @param Application $app
41
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
42
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
43
     */
44 6
    public function index(Application $app, Request $request)
45
    {
46 6
        $builder = $app->form();
47
48 6
        $event = new EventArgs(
49
            array(
50 6
                'builder' => $builder,
51
            ),
52
            $request
53
        );
54 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_INITIALIZE, $event);
55
56 6
        $form = $builder->getForm();
57
58 6
        $form->handleRequest($request);
59
60 6
        if ($form->isSubmitted() && $form->isValid()) {
61 4
            switch ($request->get('mode')) {
62 4
                case 'confirm':
63 2
                    log_info('退会確認画面表示');
64
65 2
                    return $app->render('Mypage/withdraw_confirm.twig', array(
66 2
                        'form' => $form->createView(),
67
                    ));
68
69 2
                case 'complete':
70 2
                    log_info('退会処理開始');
71
72
                    /* @var $Customer \Eccube\Entity\Customer */
73 2
                    $Customer = $app->user();
74
75
                    // 会員削除
76 2
                    $email = $Customer->getEmail();
77
                    // メールアドレスにダミーをセット
78 2
                    $Customer->setEmail(Str::random(60) . '@dummy.dummy');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
79 2
                    $Customer->setDelFlg(Constant::ENABLED);
80
81 2
                    $app['orm.em']->flush();
82
83 2
                    log_info('退会処理完了');
84
85 2
                    $event = new EventArgs(
86
                        array(
87 2
                            'form' => $form,
88 2
                            'Customer' => $Customer,
89
                        ), $request
90
                    );
91 2
                    $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE, $event);
92
93
                    // メール送信
94 2
                    $app['eccube.service.mail']->sendCustomerWithdrawMail($Customer, $email);
95
96
                    // ログアウト
97 2
                    $this->getSecurity($app)->setToken(null);
98
99 2
                    log_info('ログアウト完了');
100
101 2
                    return $app->redirect($app->url('mypage_withdraw_complete'));
102
            }
103
        }
104
105 2
        return $app->render('Mypage/withdraw.twig', array(
106 2
            'form' => $form->createView(),
107
        ));
108
    }
109
110
    /**
111
     * 退会完了画面.
112
     *
113
     * @param Application $app
114
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
115
     * @return \Symfony\Component\HttpFoundation\Response
116
     */
117 1
    public function complete(Application $app, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118
    {
119 1
        return $app->render('Mypage/withdraw_complete.twig');
120
    }
121
}
122