Failed Conditions
Pull Request — master (#1340)
by Tsuyoshi
16:42
created

ContactController::index()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 53
Code Lines 33

Duplication

Lines 8
Ratio 15.09 %

Code Coverage

Tests 9
CRAP Score 8.304

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 53
ccs 9
cts 15
cp 0.6
rs 8.7155
cc 6
eloc 33
nc 8
nop 2
crap 8.304

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;
26
27
use Eccube\Application;
28
use Symfony\Component\HttpFoundation\Request;
29
30
class ContactController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
31
{
32 5
    public function index(Application $app, Request $request)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
33
    {
34
        /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
35
        $builder = $app['form.factory']->createBuilder('contact');
36
37
        /* @var $form \Symfony\Component\Form\FormInterface */
38
        $form = $builder->getForm();
39
40
        if ($app['security']->isGranted('ROLE_USER')) {
41
            /* @var $user \Eccube\Entity\Customer */
42
            $user = $app['user'];
43
            $form->setData(array(
44
                'name01' => $user->getName01(),
45
                'name02' => $user->getName02(),
46
                'kana01' => $user->getKana01(),
47
                'kana02' => $user->getKana02(),
48
                'zip01' => $user->getZip01(),
49
                'zip02' => $user->getZip02(),
50
                'pref' => $user->getPref(),
51
                'addr01' => $user->getAddr01(),
52
                'addr02' => $user->getAddr02(),
53
                'tel01' => $user->getTel01(),
54
                'tel02' => $user->getTel02(),
55
                'tel03' => $user->getTel03(),
56
                'email' => $user->getEmail(),
57
            ));
58
        }
59
60
        $form->handleRequest($request);
61
62
        if ($form->isSubmitted() && $form->isValid()) {
63 4
            switch ($request->get('mode')) {
64 4 View Code Duplication
                case 'confirm':
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...
65
                    $builder->setAttribute('freeze', true);
66
                    $form = $builder->getForm();
67
                    $form->handleRequest($request);
68
69 1
                    return $app->render('Contact/confirm.twig', array(
70 1
                        'form' => $form->createView(),
71
                    ));
72
73 3
                case 'complete':
74
                    // メール送信
75
                    $app['eccube.service.mail']->sendrContactMail($form->getData());
76
77
                    return $app->redirect($app->url('contact_complete'));
78
            }
79
        }
80
81 1
        return $app->render('Contact/index.twig', array(
82 1
            'form' => $form->createView(),
83
        ));
84 5
    }
85
86 1
    public function complete(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
87
    {
88
        return $app->render('Contact/complete.twig');
89 1
    }
90
}
91