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) EC-CUBE CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.ec-cube.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\Admin\Customer; |
||
15 | |||
16 | use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; |
||
17 | use Eccube\Controller\AbstractController; |
||
18 | use Eccube\Entity\Customer; |
||
19 | use Eccube\Entity\CustomerAddress; |
||
20 | use Eccube\Event\EccubeEvents; |
||
21 | use Eccube\Event\EventArgs; |
||
22 | use Eccube\Form\Type\Front\CustomerAddressType; |
||
23 | use Eccube\Repository\CustomerAddressRepository; |
||
24 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
25 | use Symfony\Component\HttpFoundation\Request; |
||
26 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
27 | use Symfony\Component\Routing\Annotation\Route; |
||
28 | |||
29 | class CustomerDeliveryEditController extends AbstractController |
||
30 | { |
||
31 | /** |
||
32 | * @var CustomerAddressRepository |
||
33 | */ |
||
34 | protected $customerAddressRepository; |
||
35 | |||
36 | 2 | public function __construct( |
|
37 | CustomerAddressRepository $customerAddressRepository |
||
38 | ) { |
||
39 | 2 | $this->customerAddressRepository = $customerAddressRepository; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * お届け先編集画面. |
||
44 | * |
||
45 | * @Route("/%eccube_admin_route%/customer/{id}/delivery/new", name="admin_customer_delivery_new", requirements={"id" = "\d+"}) |
||
46 | * @Route("/%eccube_admin_route%/customer/{id}/delivery/{did}/edit", name="admin_customer_delivery_edit", requirements={"id" = "\d+", "did" = "\d+"}) |
||
47 | * @Template("@admin/Customer/delivery_edit.twig") |
||
48 | */ |
||
49 | 2 | public function edit(Request $request, Customer $Customer, $did = null) |
|
50 | { |
||
51 | // 配送先住所最大値判定 |
||
52 | // $idが存在する際は、追加処理ではなく、編集の処理ため本ロジックスキップ |
||
53 | 2 | View Code Duplication | if (is_null($did)) { |
54 | 2 | $addressCurrNum = count($Customer->getCustomerAddresses()); |
|
55 | 2 | $addressMax = $this->eccubeConfig['eccube_deliv_addr_max']; |
|
56 | 2 | if ($addressCurrNum >= $addressMax) { |
|
57 | 2 | throw new NotFoundHttpException(); |
|
58 | 2 | } |
|
59 | $CustomerAddress = new CustomerAddress(); |
||
60 | $CustomerAddress->setCustomer($Customer); |
||
61 | } else { |
||
62 | $CustomerAddress = $this->customerAddressRepository->findOneBy( |
||
63 | [ |
||
64 | 'id' => $did, |
||
65 | 'Customer' => $Customer, |
||
66 | ] |
||
67 | 2 | ); |
|
68 | if (!$CustomerAddress) { |
||
69 | 2 | throw new NotFoundHttpException(); |
|
70 | 2 | } |
|
71 | } |
||
72 | 2 | ||
73 | $builder = $this->formFactory |
||
74 | 2 | ->createBuilder(CustomerAddressType::class, $CustomerAddress); |
|
75 | 2 | ||
76 | 2 | $event = new EventArgs( |
|
77 | [ |
||
78 | 2 | 'builder' => $builder, |
|
79 | 'Customer' => $Customer, |
||
80 | 'CustomerAddress' => $CustomerAddress, |
||
81 | 2 | ], |
|
82 | $request |
||
83 | 2 | ); |
|
84 | |||
85 | 2 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELIVERY_EDIT_INDEX_INITIALIZE, $event); |
|
86 | 1 | ||
87 | 1 | $form = $builder->getForm(); |
|
88 | 1 | $form->handleRequest($request); |
|
89 | |||
90 | 1 | if ($form->isSubmitted() && $form->isValid()) { |
|
91 | 1 | log_info('お届け先登録開始', [$did]); |
|
92 | |||
93 | 1 | $this->entityManager->persist($CustomerAddress); |
|
94 | $this->entityManager->flush(); |
||
95 | 1 | ||
96 | log_info('お届け先登録完了', [$did]); |
||
97 | 1 | ||
98 | 1 | $event = new EventArgs( |
|
99 | 1 | [ |
|
100 | 'form' => $form, |
||
101 | 1 | 'Customer' => $Customer, |
|
102 | 'CustomerAddress' => $CustomerAddress, |
||
103 | 1 | ], |
|
104 | $request |
||
105 | 1 | ); |
|
106 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELIVERY_EDIT_INDEX_COMPLETE, $event); |
||
107 | 1 | ||
108 | 1 | $this->addSuccess('admin.common.save_complete', 'admin'); |
|
109 | 1 | ||
110 | return $this->redirect($this->generateUrl('admin_customer_delivery_edit', [ |
||
111 | 'id' => $Customer->getId(), |
||
112 | 'did' => $CustomerAddress->getId(), |
||
113 | ])); |
||
114 | } |
||
115 | |||
116 | return [ |
||
117 | 1 | 'form' => $form->createView(), |
|
118 | 1 | 'Customer' => $Customer, |
|
119 | 1 | 'CustomerAddress' => $CustomerAddress, |
|
120 | ]; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @Route("/%eccube_admin_route%/customer/{id}/delivery/{did}/delete", requirements={"id" = "\d+", "did" = "\d+"}, name="admin_customer_delivery_delete", methods={"DELETE"}) |
||
125 | */ |
||
126 | public function delete(Request $request, Customer $Customer, $did) |
||
127 | { |
||
128 | $this->isTokenValid(); |
||
129 | |||
130 | log_info('お届け先削除開始', [$did]); |
||
131 | |||
132 | $CustomerAddress = $this->customerAddressRepository->find($did); |
||
133 | if (is_null($CustomerAddress)) { |
||
134 | throw new NotFoundHttpException(); |
||
135 | } else { |
||
136 | if ($CustomerAddress->getCustomer()->getId() != $Customer->getId()) { |
||
137 | $this->deleteMessage(); |
||
138 | |||
139 | return $this->redirect($this->generateUrl('admin_customer_edit', ['id' => $Customer->getId()])); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | try { |
||
144 | $this->customerAddressRepository->delete($CustomerAddress); |
||
145 | $this->addSuccess('admin.common.delete_complete', 'admin'); |
||
146 | } catch (ForeignKeyConstraintViolationException $e) { |
||
147 | log_error('お届け先削除失敗', [$e], 'admin'); |
||
0 ignored issues
–
show
|
|||
148 | |||
149 | $message = trans('admin.common.delete_error_foreign_key', ['%name%' => trans('admin.customer.customer_address')]); |
||
150 | $this->addError($message, 'admin'); |
||
151 | } |
||
152 | |||
153 | log_info('お届け先削除完了', [$did]); |
||
154 | |||
155 | $event = new EventArgs( |
||
156 | [ |
||
157 | 'Customer' => $Customer, |
||
158 | 'CustomerAddress' => $CustomerAddress, |
||
159 | ], |
||
160 | $request |
||
161 | ); |
||
162 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELIVERY_DELETE_COMPLETE, $event); |
||
163 | |||
164 | return $this->redirect($this->generateUrl('admin_customer_edit', ['id' => $Customer->getId()])); |
||
165 | } |
||
166 | } |
||
167 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.