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

ChangeController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 4
cts 4
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\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);
0 ignored issues
show
Documentation introduced by
$Customer is of type null|object, but the function expects a object<Symfony\Component...r\UserInterface>|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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
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...
130
    {
131 1
        return [];
132
    }
133
}
134