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

MemberController::up()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 13

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 3
dl 23
loc 23
ccs 12
cts 12
cp 1
crap 4
rs 8.7972
c 0
b 0
f 0
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\Controller\Admin\Setting\System;
25
26
use Eccube\Application;
27
use Eccube\Controller\AbstractController;
28
use Eccube\Event\EccubeEvents;
29
use Eccube\Event\EventArgs;
30
use Eccube\Form\Type\Admin\MemberType;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
33
34
class MemberController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
35
{
36
    public function __construct()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
    }
39
40 1 View Code Duplication
    public function index(Application $app, Request $request)
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...
introduced by
Missing function doc comment
Loading history...
41
    {
42 1
        $Members = $app['eccube.repository.member']->findBy(array(), array('rank' => 'DESC'));
43
44 1
        $builder = $app['form.factory']->createBuilder();
45
46 1
        $event = new EventArgs(
47
            array(
48 1
                'builder' => $builder,
49 1
                'Members' => $Members,
50
            ),
51 1
            $request
52
        );
53 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MEMBER_INDEX_INITIALIZE, $event);
54
55 1
        $form = $builder->getForm();
56
57 1
        return $app->render('Setting/System/member.twig', array(
58 1
            'form' => $form->createView(),
59 1
            'Members' => $Members,
60
        ));
61
    }
62
63 7
    public function edit(Application $app, Request $request, $id = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
64
    {
65 7
        $previous_password = null;
66 7
        if ($id) {
67 4
            $Member = $app['eccube.repository.member']->find($id);
68 4
            if (!$Member) {
69 1
                throw new NotFoundHttpException();
70
            }
71 3
            $previous_password = $Member->getPassword();
72 3
            $Member->setPassword($app['config']['default_password']);
73
        } else {
74 3
            $Member = new \Eccube\Entity\Member();
75
        }
76
77 6
        $LoginMember = clone $app->user();
78 6
        $app['orm.em']->detach($LoginMember);
79
80 6
        $builder = $app['form.factory']
81 6
            ->createBuilder(MemberType::class, $Member);
82
83 6
        $event = new EventArgs(
84
            array(
85 6
                'builder' => $builder,
86 6
                'Member' => $Member,
87
            ),
88 6
            $request
89
        );
90 6
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MEMBER_EDIT_INITIALIZE, $event);
91
92 6
        $form = $builder->getForm();
93
94 6
        if ('POST' === $request->getMethod()) {
95 4
            $form->handleRequest($request);
96 4
            if ($form->isValid()) {
97 2
                if (!is_null($previous_password)
98 2
                    && $Member->getpassword() === $app['config']['default_password']) {
99
                    // 編集時にPWを変更していなければ
100
                    // 変更前のパスワード(暗号化済み)をセット
101 1
                    $Member->setPassword($previous_password);
102
                } else {
103 1
                    $salt = $Member->getSalt();
104 1
                    if (!isset($salt)) {
105 1
                        $salt = $app['eccube.repository.member']->createSalt(5);
106 1
                        $Member->setSalt($salt);
107
                    }
108
109
                    // 入力されたPWを暗号化してセット
110 1
                    $password = $app['eccube.repository.member']->encryptPassword($Member);
111 1
                    $Member->setPassword($password);
112
                }
113 2
                $status = $app['eccube.repository.member']->save($Member);
114
115 2
                if ($status) {
116 2
                    $event = new EventArgs(
117
                        array(
118 2
                            'form' => $form,
119 2
                            'Member' => $Member,
120
                        ),
121 2
                        $request
122
                    );
123 2
                    $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MEMBER_EDIT_COMPLETE, $event);
124
125 2
                    $app->addSuccess('admin.member.save.complete', 'admin');
126
127 2
                    return $app->redirect($app->url('admin_setting_system_member'));
128
                } else {
129
                    $app->addError('admin.member.save.error', 'admin');
130
                }
131
            }
132
        }
133
134 4
        $app['security.token_storage']->getToken()->setUser($LoginMember);
135
136 4
        return $app->render('Setting/System/member_edit.twig', array(
137 4
            'form' => $form->createView(),
138 4
            'Member' => $Member,
139
        ));
140
141
    }
142
143 3 View Code Duplication
    public function up(Application $app, Request $request, $id)
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...
introduced by
Missing function doc comment
Loading history...
144
    {
145 3
        $this->isTokenValid($app);
146
147 3
        $TargetMember = $app['eccube.repository.member']->find($id);
148
149 3
        if (!$TargetMember) {
150 1
            throw new NotFoundHttpException();
151
        }
152
153 2
        $status = false;
154 2
        if ('PUT' === $request->getMethod()) {
155 2
            $status = $app['eccube.repository.member']->up($TargetMember);
156
        }
157
158 2
        if ($status) {
159 1
            $app->addSuccess('admin.member.up.complete', 'admin');
160
        } else {
161 1
            $app->addError('admin.member.up.error', 'admin');
162
        }
163
164 2
        return $app->redirect($app->url('admin_setting_system_member'));
165
    }
166
167 4 View Code Duplication
    public function down(Application $app, Request $request, $id)
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...
introduced by
Missing function doc comment
Loading history...
168
    {
169 4
        $this->isTokenValid($app);
170
171 4
        $TargetMember = $app['eccube.repository.member']->find($id);
172
173 4
        if (!$TargetMember) {
174 1
            throw new NotFoundHttpException();
175
        }
176
177 3
        $status = false;
178 3
        if ('PUT' === $request->getMethod()) {
179 3
            $status = $app['eccube.repository.member']->down($TargetMember);
180
        }
181
182 3
        if ($status) {
183 2
            $app->addSuccess('admin.member.down.complete', 'admin');
184
        } else {
185 1
            $app->addError('admin.member.down.error', 'admin');
186
        }
187
188 3
        return $app->redirect($app->url('admin_setting_system_member'));
189
    }
190
191 2
    public function delete(Application $app, Request $request, $id)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
192
    {
193 2
        $this->isTokenValid($app);
194
195 2
        $TargetMember = $app['eccube.repository.member']->find($id);
196 2
        if (!$TargetMember) {
197 1
            $app->deleteMessage();
198 1
            return $app->redirect($app->url('admin_setting_system_member'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
199
        }
200
201 1
        $event = new EventArgs(
202
            array(
203 1
                'TargetMember' => $TargetMember,
204
            ),
205 1
            $request
206
        );
207 1
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MEMBER_DELETE_INITIALIZE, $event);
208
209 1
        $status = $app['eccube.repository.member']->delete($TargetMember);
210
211 1
        if ($status) {
212 1
            $app->addSuccess('admin.member.delete.complete', 'admin');
213 1
            $event = new EventArgs(
214 1
                array(),
215 1
                $request
216
            );
217 1
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MEMBER_DELETE_COMPLETE, $event);
218
        } else {
219
            $app->addError('admin.member.delete.error', 'admin');
220
        }
221
222 1
        return $app->redirect($app->url('admin_setting_system_member'));
223
    }
224
}