Completed
Pull Request — experimental/sf (#3397)
by
unknown
308:10 queued 300:55
created

WithdrawController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
dl 0
loc 113
ccs 38
cts 40
cp 0.95
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 12

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B index() 0 68 5
A complete() 0 4 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\Mypage;
15
16
use Eccube\Controller\AbstractController;
17
use Eccube\Entity\Master\CustomerStatus;
18
use Eccube\Event\EccubeEvents;
19
use Eccube\Event\EventArgs;
20
use Eccube\Repository\Master\CustomerStatusRepository;
21
use Eccube\Service\MailService;
22
use Eccube\Util\StringUtil;
23
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
24
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
25
use Symfony\Component\HttpFoundation\Request;
26
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
27
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
28
29
class WithdrawController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
30
{
31
    /**
32
     * @var MailService
33
     */
34
    protected $mailService;
35
36
    /**
37
     * @var CustomerStatusRepository
38
     */
39
    protected $customerStatusRepository;
40
41
    /**
42
     * @var TokenStorage
43
     */
44
    protected $tokenStorage;
45
46 4
    public function __construct(
47
        MailService $mailService,
48
        CustomerStatusRepository $customerStatusRepository,
49
        TokenStorageInterface $tokenStorage
50
    ) {
51 4
        $this->mailService = $mailService;
52 4
        $this->customerStatusRepository = $customerStatusRepository;
53 4
        $this->tokenStorage = $tokenStorage;
0 ignored issues
show
Documentation Bug introduced by
$tokenStorage is of type object<Symfony\Component...\TokenStorageInterface>, but the property $tokenStorage was declared to be of type object<Symfony\Component...n\Storage\TokenStorage>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
54
    }
55
56
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
57
     * 退会画面.
58
     *
59
     * @Route("/mypage/withdraw", name="mypage_withdraw")
60
     * @Template("Mypage/withdraw.twig")
61
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
62 3
    public function index(Request $request)
63
    {
64 3
        $builder = $this->formFactory->createBuilder();
65
66 3
        $event = new EventArgs(
67
            [
68 3
                'builder' => $builder,
69
            ],
70 3
            $request
71
        );
72 3
        $this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_INITIALIZE, $event);
73
74 3
        $form = $builder->getForm();
75
76 3
        $form->handleRequest($request);
77
78 3
        if ($form->isSubmitted() && $form->isValid()) {
79 2
            switch ($request->get('mode')) {
80
                case 'confirm':
81 1
                    log_info('退会確認画面表示');
82
83 1
                    return $this->render(
84 1
                        'Mypage/withdraw_confirm.twig',
85
                        [
86 1
                            'form' => $form->createView(),
87
                        ]
88
                    );
89
90
                case 'complete':
91 1
                    log_info('退会処理開始');
92
93
                    /* @var $Customer \Eccube\Entity\Customer */
94 1
                    $Customer = $this->getUser();
95 1
                    $email = $Customer->getEmail();
96
97
                    // 退会ステータスに変更
98 1
                    $CustomerStatus = $this->customerStatusRepository->find(CustomerStatus::WITHDRAWING);
99 1
                    $Customer->setStatus($CustomerStatus);
100 1
                    $Customer->setEmail(StringUtil::random(60).'@dummy.dummy');
101
102 1
                    $this->entityManager->flush();
103
104 1
                    log_info('退会処理完了');
105
106 1
                    $event = new EventArgs(
107
                        [
108 1
                            'form' => $form,
109 1
                            'Customer' => $Customer,
110 1
                        ], $request
111
                    );
112 1
                    $this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE, $event);
113
114
                    // メール送信
115 1
                    $this->mailService->sendCustomerWithdrawMail($Customer, $email);
116
117
                    // ログアウト
118 1
                    $this->tokenStorage->setToken(null);
119
120 1
                    log_info('ログアウト完了');
121
122 1
                    return $this->redirect($this->generateUrl('mypage_withdraw_complete'));
123
            }
124
        }
125
126
        return [
127 1
            'form' => $form->createView(),
128
        ];
129
    }
130
131
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
132
     * 退会完了画面.
133
     *
134
     * @Route("/mypage/withdraw_complete", name="mypage_withdraw_complete")
135
     * @Template("Mypage/withdraw_complete.twig")
136
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
137 1
    public function complete(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
138
    {
139 1
        return [];
140
    }
141
}
142