Completed
Push — 4.0 ( b48f64...137622 )
by chihiro
20:21 queued 10s
created

src/Eccube/Controller/Mypage/ChangeController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Event\EccubeEvents;
18
use Eccube\Event\EventArgs;
19
use Eccube\Form\Type\Front\EntryType;
20
use Eccube\Repository\CustomerRepository;
21
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
22
use Symfony\Component\HttpFoundation\Request;
23
use Symfony\Component\Routing\Annotation\Route;
24
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
25
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
26
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
27
28
class ChangeController extends AbstractController
29
{
30
    /**
31
     * @var TokenStorage
32
     */
33
    protected $tokenStorage;
34
35
    /**
36
     * @var CustomerRepository
37
     */
38
    protected $customerRepository;
39
40
    /**
41
     * @var EncoderFactoryInterface
42
     */
43
    protected $encoderFactory;
44
45 5
    public function __construct(
46
        CustomerRepository $customerRepository,
47
        EncoderFactoryInterface $encoderFactory,
48
        TokenStorageInterface $tokenStorage
49
    ) {
50 5
        $this->customerRepository = $customerRepository;
51 5
        $this->encoderFactory = $encoderFactory;
52 5
        $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...
53
    }
54
55
    /**
56
     * 会員情報編集画面.
57
     *
58
     * @Route("/mypage/change", name="mypage_change")
59
     * @Template("Mypage/change.twig")
60
     */
61 4
    public function index(Request $request)
62
    {
63 4
        $Customer = $this->getUser();
64 4
        $LoginCustomer = clone $Customer;
65 4
        $this->entityManager->detach($LoginCustomer);
66
67 4
        $previous_password = $Customer->getPassword();
68 4
        $Customer->setPassword($this->eccubeConfig['eccube_default_password']);
69
70
        /* @var $builder \Symfony\Component\Form\FormBuilderInterface */
71 4
        $builder = $this->formFactory->createBuilder(EntryType::class, $Customer);
72
73 4
        $event = new EventArgs(
74
            [
75 4
                'builder' => $builder,
76 4
                'Customer' => $Customer,
77
            ],
78 4
            $request
79
        );
80 4
        $this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_INITIALIZE, $event);
81
82
        /* @var $form \Symfony\Component\Form\FormInterface */
83 4
        $form = $builder->getForm();
84 4
        $form->handleRequest($request);
85
86 4
        if ($form->isSubmitted() && $form->isValid()) {
87 2
            log_info('会員編集開始');
88
89 2 View Code Duplication
            if ($Customer->getPassword() === $this->eccubeConfig['eccube_default_password']) {
90 1
                $Customer->setPassword($previous_password);
91
            } else {
92 1
                $encoder = $this->encoderFactory->getEncoder($Customer);
93 1
                if ($Customer->getSalt() === null) {
94
                    $Customer->setSalt($encoder->createSalt());
95
                }
96 1
                $Customer->setPassword(
97 1
                    $encoder->encodePassword($Customer->getPassword(), $Customer->getSalt())
98
                );
99
            }
100 2
            $this->entityManager->flush();
101
102 2
            log_info('会員編集完了');
103
104 2
            $event = new EventArgs(
105
                [
106 2
                    'form' => $form,
107 2
                    'Customer' => $Customer,
108
                ],
109 2
                $request
110
            );
111 2
            $this->eventDispatcher->dispatch(EccubeEvents::FRONT_MYPAGE_CHANGE_INDEX_COMPLETE, $event);
112
113 2
            return $this->redirect($this->generateUrl('mypage_change_complete'));
114
        }
115
116 2
        $this->tokenStorage->getToken()->setUser($LoginCustomer);
117
118
        return [
119 2
            'form' => $form->createView(),
120
        ];
121
    }
122
123
    /**
124
     * 会員情報編集完了画面.
125
     *
126
     * @Route("/mypage/change_complete", name="mypage_change_complete")
127
     * @Template("Mypage/change_complete.twig")
128
     */
129 1
    public function complete(Request $request)
0 ignored issues
show
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...
130
    {
131 1
        return [];
132
    }
133
}
134