Failed Conditions
Pull Request — experimental/3.1 (#2449)
by Kiyotaka
52:40
created

ChangeController::index()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 61
Code Lines 36

Duplication

Lines 10
Ratio 16.39 %

Code Coverage

Tests 32
CRAP Score 5.0006

Importance

Changes 0
Metric Value
cc 5
eloc 36
nc 4
nop 2
dl 10
loc 61
ccs 32
cts 33
cp 0.9697
crap 5.0006
rs 8.6806
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\Controller\AbstractController;
29
use Eccube\Event\EccubeEvents;
30
use Eccube\Event\EventArgs;
31
use Eccube\Form\Type\Front\EntryType;
32
use Symfony\Component\HttpFoundation\Request;
33
34
class ChangeController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
35
{
36
    /**
37
     * 会員情報編集画面.
38
     *
39
     * @param Application $app
40
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
41
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
42
     */
43 4
    public function index(Application $app, Request $request)
44
    {
45 4
        $Customer = $app->user();
46 4
        $LoginCustomer = clone $Customer;
47 4
        $app['orm.em']->detach($LoginCustomer);
48
49 4
        $previous_password = $Customer->getPassword();
50 4
        $Customer->setPassword($app['config']['default_password']);
51
52
        /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
53 4
        $builder = $app['form.factory']->createBuilder(EntryType::class, $Customer);
54
55 4
        $event = new EventArgs(
56
            array(
57 4
                'builder' => $builder,
58 4
                'Customer' => $Customer,
59
            ),
60 4
            $request
61
        );
62 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_INITIALIZE, $event);
63
64
        /* @var $form \Symfony\Component\Form\FormInterface */
65 4
        $form = $builder->getForm();
66 4
        $form->handleRequest($request);
67
68 4
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
69
70 2
            log_info('会員編集開始');
71
72 2 View Code Duplication
            if ($Customer->getPassword() === $app['config']['default_password']) {
73 1
                $Customer->setPassword($previous_password);
74
            } else {
75 1
                if ($Customer->getSalt() === null) {
76
                    $Customer->setSalt($app['eccube.repository.customer']->createSalt(5));
77
                }
78 1
                $Customer->setPassword(
79 1
                    $app['eccube.repository.customer']->encryptPassword($app, $Customer)
80
                );
81
            }
82 2
            $app['orm.em']->flush();
83
84 2
            log_info('会員編集完了');
85
86 2
            $event = new EventArgs(
87
                array(
88 2
                    'form' => $form,
89 2
                    'Customer' => $Customer,
90
                ),
91 2
                $request
92
            );
93 2
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_COMPLETE, $event);
94
95 2
            return $app->redirect($app->url('mypage_change_complete'));
96
        }
97
98 2
        $app['security.token_storage']->getToken()->setUser($LoginCustomer);
99
100 2
        return $app->render('Mypage/change.twig', array(
101 2
            'form' => $form->createView(),
102
        ));
103
    }
104
105
    /**
106
     * 会員情報編集完了画面.
107
     *
108
     * @param Application $app
109
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
110
     * @return \Symfony\Component\HttpFoundation\Response
111
     */
112 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...
113
    {
114 1
        return $app->render('Mypage/change_complete.twig');
115
    }
116
}
117