Completed
Push — master ( 52f07d...bfea6b )
by Kentaro
156:14 queued 96:48
created

ChangeController::index()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 57
Code Lines 34

Duplication

Lines 10
Ratio 17.54 %

Code Coverage

Tests 7
CRAP Score 10.0876

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 10
loc 57
ccs 7
cts 17
cp 0.4118
rs 8.7433
cc 5
eloc 34
nc 4
nop 2
crap 10.0876

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