Failed Conditions
Pull Request — experimental/sf (#3241)
by k-yamamura
43:19 queued 23:09
created

ContactController::complete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Controller;
15
16
use Eccube\Entity\Customer;
17
use Eccube\Event\EccubeEvents;
18
use Eccube\Event\EventArgs;
19
use Eccube\Form\Type\Front\ContactType;
20
use Eccube\Service\MailService;
21
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
22
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
23
use Symfony\Component\HttpFoundation\Request;
24
25
class ContactController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
26
{
27
    /**
28
     * @var MailService
29
     */
30
    protected $mailService;
31
32
    /**
33
     * ContactController constructor.
34
     *
35
     * @param MailService $mailService
36
     */
37 5
    public function __construct(
38
        MailService $mailService)
0 ignored issues
show
Coding Style introduced by
The closing parenthesis of a multi-line function declaration must be on a new line
Loading history...
39
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
40 5
        $this->mailService = $mailService;
41
    }
42
43
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
44
     * お問い合わせ画面.
45
     *
46
     * @Route("/contact", name="contact")
47
     * @Template("Contact/index.twig")
48
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
49 4
    public function index(Request $request)
50
    {
51 4
        $builder = $this->formFactory->createBuilder(ContactType::class);
52
53 4
        if ($this->isGranted('ROLE_USER')) {
54
            /** @var Customer $user */
55 1
            $user = $this->getUser();
56 1
            $builder->setData(
57
                [
58 1
                    'name01' => $user->getName01(),
59 1
                    'name02' => $user->getName02(),
60 1
                    'kana01' => $user->getKana01(),
61 1
                    'kana02' => $user->getKana02(),
62 1
                    'postal_code' => $user->getPostalCode(),
63 1
                    'pref' => $user->getPref(),
64 1
                    'addr01' => $user->getAddr01(),
65 1
                    'addr02' => $user->getAddr02(),
66 1
                    'phone_number' => $user->getPhoneNumber(),
67 1
                    'email' => $user->getEmail(),
68
                ]
69
            );
70
        }
71
72
        // FRONT_CONTACT_INDEX_INITIALIZE
73 4
        $event = new EventArgs(
74
            [
75 4
                'builder' => $builder,
76
            ],
77 4
            $request
78
        );
79 4
        $this->eventDispatcher->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE, $event);
80
81 4
        $form = $builder->getForm();
82 4
        $form->handleRequest($request);
83
84 4
        if ($form->isSubmitted() && $form->isValid()) {
85 3
            switch ($request->get('mode')) {
86
                case 'confirm':
87
                    $builder->setAttribute('freeze', true);
88
                    $form = $builder->getForm();
89
                    $form->handleRequest($request);
90
91
                    return $this->render('Contact/confirm.twig', [
92
                        'form' => $form->createView(),
93
                    ]);
94
95
                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...
96
97 3
                    $data = $form->getData();
98
99 3
                    $event = new EventArgs(
100
                        [
101 3
                            'form' => $form,
102 3
                            'data' => $data,
103
                        ],
104 3
                        $request
105
                    );
106 3
                    $this->eventDispatcher->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE, $event);
107
108 3
                    $data = $event->getArgument('data');
109
110
                    // メール送信
111 3
                    $this->mailService->sendContactMail($data);
112
113 3
                    return $this->redirect($this->generateUrl('contact_complete'));
114
            }
115
        }
116
117
        return [
118 1
            'form' => $form->createView(),
119
        ];
120
    }
121
122
    /**
123
     * お問い合わせ完了画面.
124
     *
125
     * @Route("/contact/complete", name="contact_complete")
126
     * @Template("Contact/complete.twig")
127
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
128 1
    public function complete()
129
    {
130 1
        return [];
131
    }
132
}
133