Completed
Pull Request — master (#1778)
by Kentaro
117:49 queued 111:15
created

MailController::index()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 63
Code Lines 36

Duplication

Lines 28
Ratio 44.44 %

Code Coverage

Tests 38
CRAP Score 6.0006

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 28
loc 63
ccs 38
cts 39
cp 0.9744
rs 8.6498
cc 6
eloc 36
nc 9
nop 3
crap 6.0006

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\Admin\Setting\Shop;
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
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
33
34
class MailController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
35
{
36 5
    public function index(Application $app, Request $request, $id = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38 5
        $Mail = null;
39
40 5
        if ($id) {
41 3
            $Mail = $app['orm.em']
42 3
                ->getRepository('\Eccube\Entity\MailTemplate')
43 3
                ->find($id);
44 3
            if (is_null($Mail)) {
45 1
                throw new NotFoundHttpException();
46
            }
47 2
        }
48
49 4
        $builder = $app['form.factory']
50 4
            ->createBuilder('mail', $Mail);
51
52 4
        $event = new EventArgs(
53
            array(
54 4
                'builder' => $builder,
55 4
                'Mail' => $Mail,
56 4
            ),
57
            $request
58 4
        );
59 4
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_MAIL_INDEX_INITIALIZE, $event);
60
61 4
        $form = $builder->getForm();
62
63 4
        $form['template']->setData($Mail);
64
65 4 View Code Duplication
        if ('POST' === $request->getMethod()) {
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...
66 2
            $form->handleRequest($request);
67
68
            // 新規登録は現時点では未実装とする.
69 2
            if (is_null($Mail)) {
70 1
                $app->addError('admin.shop.mail.save.error', 'admin');
71
72 1
                return $app->redirect($app->url('admin_setting_shop_mail'));
73
            }
74
75 1
            if ($form->isValid()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
76
77 1
                $app['orm.em']->flush();
78
79 1
                $event = new EventArgs(
80
                    array(
81 1
                        'form' => $form,
82 1
                        'Mail' => $Mail,
83 1
                    ),
84
                    $request
85 1
                );
86 1
                $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_MAIL_INDEX_COMPLETE, $event);
87
88 1
                $app->addSuccess('admin.shop.mail.save.complete', 'admin');
89
90 1
                return $app->redirect($app->url('admin_setting_shop_mail_edit', array('id' => $id)));
91
            }
92
        }
93
94 2
        return $app->render('Setting/Shop/mail.twig', array(
95 2
            'form' => $form->createView(),
96 2
            'id' => $id,
97 2
        ));
98
    }
99
}
100