Completed
Push — experimental/sf ( 2a520b...c0fd88 )
by
unknown
262:36 queued 254:30
created

OrderController::updateOrderStatus()   B

Complexity

Conditions 11
Paths 39

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
nc 39
nop 2
dl 0
loc 44
ccs 0
cts 26
cp 0
crap 132
rs 7.3166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Admin\Order;
15
16
use Eccube\Common\Constant;
17
use Eccube\Controller\AbstractController;
18
use Eccube\Entity\Csv;
19
use Eccube\Entity\ExportCsvRow;
20
use Eccube\Entity\Master\CsvType;
21
use Eccube\Entity\OrderItem;
22
use Eccube\Event\EccubeEvents;
23
use Eccube\Event\EventArgs;
24
use Eccube\Form\Type\Admin\SearchOrderType;
25
use Eccube\Repository\CustomerRepository;
26
use Eccube\Repository\Master\OrderStatusRepository;
27
use Eccube\Repository\Master\PageMaxRepository;
28
use Eccube\Repository\Master\ProductStatusRepository;
29
use Eccube\Repository\Master\SexRepository;
30
use Eccube\Repository\OrderRepository;
31
use Eccube\Repository\PaymentRepository;
32
use Eccube\Service\CsvExportService;
33
use Eccube\Service\OrderStateMachine;
34
use Eccube\Util\FormUtil;
35
use Knp\Component\Pager\PaginatorInterface;
36
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
37
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
38
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
39
use Symfony\Component\HttpFoundation\Response;
40
use Symfony\Component\HttpFoundation\Request;
41
use Symfony\Component\HttpFoundation\StreamedResponse;
42
use Eccube\Entity\Master\OrderStatus;
43
use Symfony\Component\HttpFoundation\RedirectResponse;
44
use Eccube\Entity\Order;
45
use Eccube\Entity\Shipping;
46
use Eccube\Service\PurchaseFlow\PurchaseContext;
47
use Eccube\Service\PurchaseFlow\PurchaseFlow;
48
use Eccube\Service\PurchaseFlow\PurchaseException;
49
use Symfony\Component\Validator\Constraints as Assert;
50
use Symfony\Component\Validator\Validator\ValidatorInterface;
51
52
class OrderController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
53
{
54
    /**
55
     * @var PurchaseFlow
56
     */
57
    protected $purchaseFlow;
58
59
    /**
60
     * @var CsvExportService
61
     */
62
    protected $csvExportService;
63
64
    /**
65
     * @var CustomerRepository
66
     */
67
    protected $customerRepository;
68
69
    /**
70
     * @var PaymentRepository
71
     */
72
    protected $paymentRepository;
73
74
    /**
75
     * @var SexRepository
76
     */
77
    protected $sexRepository;
78
79
    /**
80
     * @var OrderStatusRepository
81
     */
82
    protected $orderStatusRepository;
83
84
    /**
85
     * @var PageMaxRepository
86
     */
87
    protected $pageMaxRepository;
88
89
    /**
90
     * @var ProductStatusRepository
91
     */
92
    protected $productStatusRepository;
93
94
    /**
95
     * @var OrderRepository
96
     */
97
    protected $orderRepository;
98
99
    /**
100
     * @var ValidatorInterface
101
     */
102
    protected $validator;
103
104
    /**
105
     * @var OrderStateMachine
106
     */
107
    protected $orderStateMachine;
108
109
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$validator" missing
Loading history...
introduced by
Doc comment for parameter "$orderStateMachine" missing
Loading history...
110
     * OrderController constructor.
111
     *
112
     * @param PurchaseFlow $orderPurchaseFlow
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
113
     * @param CsvExportService $csvExportService
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
114
     * @param CustomerRepository $customerRepository
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
115
     * @param PaymentRepository $paymentRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
116
     * @param SexRepository $sexRepository
0 ignored issues
show
introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
117
     * @param OrderStatusRepository $orderStatusRepository
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
118
     * @param PageMaxRepository $pageMaxRepository
0 ignored issues
show
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
119
     * @param ProductStatusRepository $productStatusRepository
120
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
121
     * @param OrderStateMachine $orderStateMachine;
0 ignored issues
show
Documentation introduced by
There is no parameter named $orderStateMachine;. Did you maybe mean $orderStateMachine?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
introduced by
Doc comment for parameter $orderStateMachine; does not match actual variable name $validator
Loading history...
122
     */
123 14
    public function __construct(
124
        PurchaseFlow $orderPurchaseFlow,
125
        CsvExportService $csvExportService,
126
        CustomerRepository $customerRepository,
127
        PaymentRepository $paymentRepository,
128
        SexRepository $sexRepository,
129
        OrderStatusRepository $orderStatusRepository,
130
        PageMaxRepository $pageMaxRepository,
131
        ProductStatusRepository $productStatusRepository,
132
        OrderRepository $orderRepository,
133
        ValidatorInterface $validator,
134
        OrderStateMachine $orderStateMachine
135
    ) {
136 14
        $this->purchaseFlow = $orderPurchaseFlow;
137 14
        $this->csvExportService = $csvExportService;
138 14
        $this->customerRepository = $customerRepository;
139 14
        $this->paymentRepository = $paymentRepository;
140 14
        $this->sexRepository = $sexRepository;
141 14
        $this->orderStatusRepository = $orderStatusRepository;
142 14
        $this->pageMaxRepository = $pageMaxRepository;
143 14
        $this->productStatusRepository = $productStatusRepository;
144 14
        $this->orderRepository = $orderRepository;
145 14
        $this->validator = $validator;
146 14
        $this->orderStateMachine = $orderStateMachine;
147
    }
148
149
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
introduced by
Doc comment for parameter "$page_no" missing
Loading history...
introduced by
Doc comment for parameter "$paginator" missing
Loading history...
150
     * 受注一覧画面.
151
     *
152
     * - 検索条件, ページ番号, 表示件数はセッションに保持されます.
153
     * - クエリパラメータでresume=1が指定された場合、検索条件, ページ番号, 表示件数をセッションから復旧します.
154
     * - 各データの, セッションに保持するアクションは以下の通りです.
155
     *   - 検索ボタン押下時
156
     *      - 検索条件をセッションに保存します
157
     *      - ページ番号は1で初期化し、セッションに保存します。
158
     *   - 表示件数変更時
159
     *      - クエリパラメータpage_countをセッションに保存します。
160
     *      - ただし, mtb_page_maxと一致しない場合, eccube_default_page_countが保存されます.
161
     *   - ページング時
162
     *      - URLパラメータpage_noをセッションに保存します.
163
     *   - 初期表示
164
     *      - 検索条件は空配列, ページ番号は1で初期化し, セッションに保存します.
165
     *
166
     * @Route("/%eccube_admin_route%/order", name="admin_order")
167
     * @Route("/%eccube_admin_route%/order/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_order_page")
168
     * @Template("@admin/Order/index.twig")
169
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
170 8
    public function index(Request $request, $page_no = null, PaginatorInterface $paginator)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
171
    {
172 8
        $builder = $this->formFactory
173 8
            ->createBuilder(SearchOrderType::class);
174
175 8
        $event = new EventArgs(
176
            [
177 8
                'builder' => $builder,
178
            ],
179 8
            $request
180
        );
181 8
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE, $event);
182
183 8
        $searchForm = $builder->getForm();
184
185
        /**
186
         * ページの表示件数は, 以下の順に優先される.
187
         * - リクエストパラメータ
188
         * - セッション
189
         * - デフォルト値
190
         * また, セッションに保存する際は mtb_page_maxと照合し, 一致した場合のみ保存する.
191
         **/
192 8
        $page_count = $this->session->get('eccube.admin.order.search.page_count',
193 8
                $this->eccubeConfig->get('eccube_default_page_count'));
194
195 8
        $page_count_param = (int) $request->get('page_count');
196 8
        $pageMaxis = $this->pageMaxRepository->findAll();
197
198 8
        if ($page_count_param) {
199 1
            foreach ($pageMaxis as $pageMax) {
200 1
                if ($page_count_param == $pageMax->getName()) {
201
                    $page_count = $pageMax->getName();
202
                    $this->session->set('eccube.admin.order.search.page_count', $page_count);
203 1
                    break;
204
                }
205
            }
206
        }
207
208 8
        if ('POST' === $request->getMethod()) {
209 6
            $searchForm->handleRequest($request);
210
211 6
            if ($searchForm->isValid()) {
212
                /**
213
                 * 検索が実行された場合は, セッションに検索条件を保存する.
214
                 * ページ番号は最初のページ番号に初期化する.
215
                 */
216 5
                $page_no = 1;
217 5
                $searchData = $searchForm->getData();
218
219
                // 検索条件, ページ番号をセッションに保持.
220 5
                $this->session->set('eccube.admin.order.search', FormUtil::getViewData($searchForm));
221 5
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
222
            } else {
223
                // 検索エラーの際は, 詳細検索枠を開いてエラー表示する.
224
                return [
225 6
                    'searchForm' => $searchForm->createView(),
226
                    'pagination' => [],
227 1
                    'pageMaxis' => $pageMaxis,
228 1
                    'page_no' => $page_no,
229 1
                    'page_count' => $page_count,
230
                    'has_errors' => true,
231
                ];
232
            }
233
        } else {
234 3
            if (null !== $page_no || $request->get('resume')) {
235
                /*
236
                 * ページ送りの場合または、他画面から戻ってきた場合は, セッションから検索条件を復旧する.
237
                 */
238 1
                if ($page_no) {
239
                    // ページ送りで遷移した場合.
240 1
                    $this->session->set('eccube.admin.order.search.page_no', (int) $page_no);
241
                } else {
242
                    // 他画面から遷移した場合.
243
                    $page_no = $this->session->get('eccube.admin.order.search.page_no', 1);
244
                }
245 1
                $viewData = $this->session->get('eccube.admin.order.search', []);
246 1
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
247
            } else {
248
                /**
249
                 * 初期表示の場合.
250
                 */
251 2
                $page_no = 1;
252 2
                $viewData = [];
253
254 2
                if ($statusId = (int) $request->get('order_status_id')) {
255
                    $viewData = ['status' => $statusId];
256
                }
257
258 2
                $searchData = FormUtil::submitAndGetData($searchForm, $viewData);
259
260
                // セッション中の検索条件, ページ番号を初期化.
261 2
                $this->session->set('eccube.admin.order.search', $viewData);
262 2
                $this->session->set('eccube.admin.order.search.page_no', $page_no);
263
            }
264
        }
265
266 8
        $qb = $this->orderRepository->getQueryBuilderBySearchDataForAdmin($searchData);
267
268 8
        $event = new EventArgs(
269
            [
270 8
                'qb' => $qb,
271 8
                'searchData' => $searchData,
272
            ],
273 8
            $request
274
        );
275
276 8
        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_INDEX_SEARCH, $event);
277
278 8
        $pagination = $paginator->paginate(
279 8
            $qb,
280 8
            $page_no,
281 8
            $page_count
282
        );
283
284
        return [
285 8
            'searchForm' => $searchForm->createView(),
286 8
            'pagination' => $pagination,
287 8
            'pageMaxis' => $pageMaxis,
288 8
            'page_no' => $page_no,
289 8
            'page_count' => $page_count,
290
            'has_errors' => false,
291 8
            'OrderStatuses' => $this->orderStatusRepository->findBy([], ['sort_no' => 'ASC']),
292
        ];
293
    }
294
295
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
296
     * @Method("POST")
297
     * @Route("/%eccube_admin_route%/order/bulk_delete", name="admin_order_bulk_delete")
298
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
299 1
    public function bulkDelete(Request $request)
300
    {
301 1
        $this->isTokenValid();
302 1
        $ids = $request->get('ids');
303 1
        foreach ($ids as $order_id) {
304 1
            $Order = $this->orderRepository
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $Order is correct as $this->orderRepository->find($order_id) (which targets Doctrine\ORM\EntityRepository::find()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
305 1
                ->find($order_id);
306 1
            if ($Order) {
307 1
                $this->entityManager->remove($Order);
308 1
                log_info('受注削除', [$Order->getId()]);
309
            }
310
        }
311
312 1
        $this->entityManager->flush();
313
314 1
        $this->addSuccess('admin.order.delete.complete', 'admin');
315
316 1
        return $this->redirect($this->generateUrl('admin_order', ['resume' => Constant::ENABLED]));
317
    }
318
319
    /**
320
     * 受注CSVの出力.
321
     *
322
     * @Route("/%eccube_admin_route%/order/export/order", name="admin_order_export_order")
323
     *
324
     * @param Request $request
325
     *
326
     * @return StreamedResponse
327
     */
328 1 View Code Duplication
    public function exportOrder(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
329
    {
330 1
        $filename = 'order_'.(new \DateTime())->format('YmdHis').'.csv';
331 1
        $response = $this->exportCsv($request, CsvType::CSV_TYPE_ORDER, $filename);
332 1
        log_info('受注CSV出力ファイル名', [$filename]);
333
334 1
        return $response;
335
    }
336
337
    /**
338
     * 配送CSVの出力.
339
     *
340
     * @Route("/%eccube_admin_route%/order/export/shipping", name="admin_order_export_shipping")
341
     *
342
     * @param Request $request
343
     *
344
     * @return StreamedResponse
345
     */
346 View Code Duplication
    public function exportShipping(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
347
    {
348
        $filename = 'shipping_'.(new \DateTime())->format('YmdHis').'.csv';
349
        $response = $this->exportCsv($request, CsvType::CSV_TYPE_SHIPPING, $filename);
350
        log_info('配送CSV出力ファイル名', [$filename]);
351
352
        return $response;
353
    }
354
355
    /**
356
     * @param Request $request
357
     * @param $csvTypeId
358
     * @param $fileName
359
     *
360
     * @return StreamedResponse
361
     */
362 1
    private function exportCsv(Request $request, $csvTypeId, $fileName)
363
    {
364
        // タイムアウトを無効にする.
365 1
        set_time_limit(0);
366
367
        // sql loggerを無効にする.
368 1
        $em = $this->entityManager;
369 1
        $em->getConfiguration()->setSQLLogger(null);
370
371 1
        $response = new StreamedResponse();
372 1
        $response->setCallback(function () use ($request, $csvTypeId) {
373
            // CSV種別を元に初期化.
374 1
            $this->csvExportService->initCsvType($csvTypeId);
375
376
            // ヘッダ行の出力.
377 1
            $this->csvExportService->exportHeader();
378
379
            // 受注データ検索用のクエリビルダを取得.
380 1
            $qb = $this->csvExportService
381 1
                ->getOrderQueryBuilder($request);
382
383
            // データ行の出力.
384 1
            $this->csvExportService->setExportQueryBuilder($qb);
385 1
            $this->csvExportService->exportData(function ($entity, $csvService) use ($request) {
386 1
                $Csvs = $csvService->getCsvs();
387
388 1
                $Order = $entity;
389 1
                $OrderItems = $Order->getOrderItems();
390
391 1
                foreach ($OrderItems as $OrderItem) {
392 1
                    $ExportCsvRow = new ExportCsvRow();
393
394
                    // CSV出力項目と合致するデータを取得.
395 1
                    foreach ($Csvs as $Csv) {
396
                        // 受注データを検索.
397 1
                        $ExportCsvRow->setData($csvService->getData($Csv, $Order));
398 1
                        if ($ExportCsvRow->isDataNull()) {
399
                            // 受注データにない場合は, 受注明細を検索.
400 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $OrderItem));
401
                        }
402 1
                        if ($ExportCsvRow->isDataNull() && $Shipping = $OrderItem->getShipping()) {
403
                            // 受注明細データにない場合は, 出荷を検索.
404 1
                            $ExportCsvRow->setData($csvService->getData($Csv, $Shipping));
405
                        }
406
407 1
                        $event = new EventArgs(
408
                            [
409 1
                                'csvService' => $csvService,
410 1
                                'Csv' => $Csv,
411 1
                                'OrderItem' => $OrderItem,
412 1
                                'ExportCsvRow' => $ExportCsvRow,
413
                            ],
414 1
                            $request
415
                        );
416 1
                        $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_CSV_EXPORT_ORDER, $event);
417
418 1
                        $ExportCsvRow->pushData();
419
                    }
420
421
                    //$row[] = number_format(memory_get_usage(true));
422
                    // 出力.
423 1
                    $csvService->fputcsv($ExportCsvRow->getRow());
424
                }
425 1
            });
426 1
        });
427
428 1
        $response->headers->set('Content-Type', 'application/octet-stream');
429 1
        $response->headers->set('Content-Disposition', 'attachment; filename='.$fileName);
430 1
        $response->send();
431
432 1
        return $response;
433
    }
434
435
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Shipping" missing
Loading history...
436
     * Update to order status
437
     *
438
     * @Method("PUT")
439
     * @Route("/%eccube_admin_route%/shipping/{id}/order_status", requirements={"id" = "\d+"}, name="admin_shipping_update_order_status")
440
     *
441
     * @param Request $request
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
442
     * @param Shipping $shipping
0 ignored issues
show
Documentation introduced by
There is no parameter named $shipping. Did you maybe mean $Shipping?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
introduced by
Doc comment for parameter $shipping does not match case of actual variable name $Shipping
Loading history...
443
     *
444
     * @return RedirectResponse
445
     */
446
    public function updateOrderStatus(Request $request, Shipping $Shipping)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
447
    {
448
        if (!($request->isXmlHttpRequest() && $this->isTokenValid())) {
449
            return $this->json(['status' => 'NG'], 400);
450
        }
451
452
        $Order = $Shipping->getOrder();
453
        $OrderStatus = $this->entityManager->find(OrderStatus::class, $request->get('order_status'));
454
455
        try {
456
            // 発送済みに変更された場合は、関連する出荷がすべて出荷済みになったら OrderStatus を変更する
457
            if (OrderStatus::DELIVERED == $OrderStatus->getId()) {
458
                if (!$Shipping->getShippingDate()) {
459
                    $Shipping->setShippingDate(\DateTime());
460
                    $this->entityManager->flush($Shipping);
0 ignored issues
show
Unused Code introduced by
The call to EntityManagerInterface::flush() has too many arguments starting with $Shipping.

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.

Loading history...
461
                }
462
                $RelateShippings = $Order->getShippings();
463
                $allShipped = false;
464
                foreach ($RelateShippings as $RelateShipping) {
465
                    if (!$RelateShipping->getShippingDate()) {
466
                        continue;
467
                    }
468
                    $allShipped = true;
469
                }
470
                if ($allShipped) {
471
                    if ($this->orderStateMachine->can($Order, $OrderStatus)) {
472
                        $this->orderStateMachine->apply($Order, $OrderStatus);
473
                    }
474
                }
475
            } else {
476
                if ($this->orderStateMachine->can($Order, $OrderStatus)) {
477
                    $this->orderStateMachine->apply($Order, $OrderStatus);
478
                }
479
            }
480
            $this->entityManager->flush($Order);
0 ignored issues
show
Unused Code introduced by
The call to EntityManagerInterface::flush() has too many arguments starting with $Order.

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.

Loading history...
481
            log_info('対応状況一括変更処理完了', [$Order->getId()]);
482
        } catch (\Exception $e) {
483
            log_error('予期しないエラーです', [$e->getMessage()]);
484
485
            return $this->json(['status' => 'NG'], 500);
486
        }
487
488
        return $this->json(['status' => 'OK']);
489
    }
490
491
    /**
492
     * Bulk action to order status
493
     *
494
     * @Method("POST")
495
     * @Route("/%eccube_admin_route%/order/bulk/order-status/{id}", requirements={"id" = "\d+"}, name="admin_order_bulk_order_status")
496
     *
497
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
498
     * @param OrderStatus $OrderStatus
499
     *
500
     * @return RedirectResponse
501
     *
502
     * @deprecated 使用していない
503
     */
504 2
    public function bulkOrderStatus(Request $request, OrderStatus $OrderStatus)
505
    {
506 2
        $this->isTokenValid();
507
508
        /** @var Order[] $Orders */
509 2
        $Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]);
510
511 2
        $count = 0;
512 2
        foreach ($Orders as $Order) {
513
            try {
514
                // TODO: should support event for plugin customize
515
                // 編集前の受注情報を保持
516 2
                $OriginOrder = clone $Order;
517
518 2
                $Order->setOrderStatus($OrderStatus);
519
520 2
                $purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());
521
522 2
                $flowResult = $this->purchaseFlow->validate($Order, $purchaseContext);
523 2
                if ($flowResult->hasWarning()) {
524
                    foreach ($flowResult->getWarning() as $warning) {
525
                        $msg = $this->translator->trans('admin.order.index.bulk_warning', [
526
                          '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
527
                          '%message%' => $warning->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
528
                        ]);
529
                        $this->addWarning($msg, 'admin');
530
                    }
531
                }
532
533 2
                if ($flowResult->hasError()) {
534
                    foreach ($flowResult->getErrors() as $error) {
535
                        $msg = $this->translator->trans('admin.order.index.bulk_error', [
536
                          '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
537
                          '%message%' => $error->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 28 spaces, but found 26.
Loading history...
538
                        ]);
539
                        $this->addError($msg, 'admin');
540
                    }
541
                    continue;
542
                }
543
544
                try {
545 2
                    $this->purchaseFlow->commit($Order, $purchaseContext);
546
                } catch (PurchaseException $e) {
547
                    $msg = $this->translator->trans('admin.order.index.bulk_error', [
548
                      '%orderId%' => $Order->getId(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 22.
Loading history...
549
                      '%message%' => $e->getMessage(),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 22.
Loading history...
550
                    ]);
551
                    $this->addError($msg, 'admin');
552
                    continue;
553
                }
554
555 2
                $this->orderRepository->save($Order);
556
557 2
                $count++;
558
            } catch (\Exception $e) {
559 2
                $this->addError('#'.$Order->getId().': '.$e->getMessage(), 'admin');
560
            }
561
        }
562
        try {
563 2 View Code Duplication
            if ($count) {
564 2
                $this->entityManager->flush();
565 2
                $msg = $this->translator->trans('admin.order.index.bulk_order_status_success_count', [
566 2
                    '%count%' => $count,
567 2
                    '%status%' => $OrderStatus->getName(),
568
                ]);
569 2
                $this->addSuccess($msg, 'admin');
570
            }
571
        } catch (\Exception $e) {
572
            log_error('Bulk order status error', [$e]);
573
            $this->addError('admin.flash.register_failed', 'admin');
574
        }
575
576 2
        return $this->redirectToRoute('admin_order', ['resume' => Constant::ENABLED]);
577
    }
578
579
    /**
580
     * Update to Tracking number.
581
     *
582
     * @Method("PUT")
583
     * @Route("/%eccube_admin_route%/shipping/{id}/tracking_number", requirements={"id" = "\d+"}, name="admin_shipping_update_tracking_number")
584
     *
585
     * @param Request $request
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
586
     * @param Shipping $shipping
587
     *
588
     * @return Response
589
     */
590 2
    public function updateTrackingNumber(Request $request, Shipping $shipping)
591
    {
592 2
        if (!($request->isXmlHttpRequest() && $this->isTokenValid())) {
593
            return $this->json(['status' => 'NG'], 400);
594
        }
595
596 2
        $trackingNumber = mb_convert_kana($request->get('tracking_number'), 'a', 'utf-8');
597
        /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $errors */
598 2
        $errors = $this->validator->validate(
599 2
            $trackingNumber,
600
            [
601 2
                new Assert\Length(['max' => $this->eccubeConfig['eccube_stext_len']]),
602 2
                new Assert\Regex(
603 2
                    ['pattern' => '/^[0-9a-zA-Z-]+$/u', 'message' => trans('form.type.admin.nottrackingnumberstyle')]
604
                ),
605
            ]
606
        );
607
608 2
        if ($errors->count() != 0) {
609 1
            log_info('送り状番号入力チェックエラー');
610 1
            $messages = [];
611
            /** @var \Symfony\Component\Validator\ConstraintViolationInterface $error */
612 1
            foreach ($errors as $error) {
613 1
                $messages[] = $error->getMessage();
614
            }
615
616 1
            return $this->json(['status' => 'NG', 'messages' => $messages], 400);
617
        }
618
619
        try {
620 1
            $shipping->setTrackingNumber($trackingNumber);
621 1
            $this->entityManager->flush($shipping);
0 ignored issues
show
Unused Code introduced by
The call to EntityManagerInterface::flush() has too many arguments starting with $shipping.

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.

Loading history...
622 1
            log_info('送り状番号変更処理完了', [$shipping->getId()]);
623 1
            $message = ['status' => 'OK', 'shipping_id' => $shipping->getId(), 'tracking_number' => $trackingNumber];
624
625 1
            return $this->json($message);
626
        } catch (\Exception $e) {
627
            log_error('予期しないエラー', [$e->getMessage()]);
628
629
            return $this->json(['status' => 'NG'], 500);
630
        }
631
    }
632
}
633