ContactController::index()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 76
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 7.4262

Importance

Changes 0
Metric Value
cc 6
eloc 49
nc 8
nop 2
dl 0
loc 76
ccs 29
cts 44
cp 0.6591
crap 7.4262
rs 8.4596
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;
26
27
use Eccube\Application;
28
use Eccube\Event\EccubeEvents;
29
use Eccube\Event\EventArgs;
30
use Symfony\Component\HttpFoundation\Request;
31
32
class ContactController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
33
{
34
    /**
35
     * お問い合わせ画面.
36
     *
37
     * @param Application $app
38
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
39
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
40
     */
41 7
    public function index(Application $app, Request $request)
42
    {
43 7
        $builder = $app['form.factory']->createBuilder('contact');
44
45 7
        if ($app->isGranted('ROLE_USER')) {
46
            $user = $app['user'];
47
            $builder->setData(
48
                array(
49
                    'name01' => $user->getName01(),
50
                    'name02' => $user->getName02(),
51
                    'kana01' => $user->getKana01(),
52
                    'kana02' => $user->getKana02(),
53
                    'zip01' => $user->getZip01(),
54
                    'zip02' => $user->getZip02(),
55
                    'pref' => $user->getPref(),
56
                    'addr01' => $user->getAddr01(),
57
                    'addr02' => $user->getAddr02(),
58
                    'tel01' => $user->getTel01(),
59
                    'tel02' => $user->getTel02(),
60
                    'tel03' => $user->getTel03(),
61
                    'email' => $user->getEmail(),
62
                )
63
            );
64
        }
65
66
        // FRONT_CONTACT_INDEX_INITIALIZE
67 7
        $event = new EventArgs(
68
            array(
69 7
                'builder' => $builder,
70
            ),
71
            $request
72
        );
73 7
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE, $event);
74
75 7
        $form = $builder->getForm();
76 7
        $form->handleRequest($request);
77
78 7
        if ($form->isSubmitted() && $form->isValid()) {
79 5
            switch ($request->get('mode')) {
80 5
                case 'confirm':
81 1
                    $builder->setAttribute('freeze', true);
82 1
                    $form = $builder->getForm();
83 1
                    $form->handleRequest($request);
84 1
                    $title = 'お問い合わせ(確認ページ)';
85
86 1
                    return $app->render('Contact/confirm.twig', array(
87 1
                        'form' => $form->createView(),
88 1
                        'title' => $title,
89
                    ));
90
91 4
                case 'complete':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
92
93 4
                    $data = $form->getData();
94
95 4
                    $event = new EventArgs(
96
                        array(
97 4
                            'form' => $form,
98 4
                            'data' => $data,
99
                        ),
100
                        $request
101
                    );
102 4
                    $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE, $event);
103
104 4
                    $data = $event->getArgument('data');
105
106
                    // メール送信
107 4
                    $app['eccube.service.mail']->sendContactMail($data);
108
109 4
                    return $app->redirect($app->url('contact_complete'));
110
            }
111
        }
112
113 2
        return $app->render('Contact/index.twig', array(
114 2
            'form' => $form->createView(),
115
        ));
116
    }
117
118
    /**
119
     * お問い合わせ完了画面.
120
     *
121
     * @param Application $app
122
     * @return \Symfony\Component\HttpFoundation\Response
123
     */
124 1
    public function complete(Application $app)
125
    {
126 1
        return $app->render('Contact/complete.twig');
127
    }
128
}
129