Code Duplication    Length = 56-58 lines in 4 locations

src/Eccube/Controller/CartController.php 4 locations

@@ 178-235 (lines=58) @@
175
     * @param $productClassId
176
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
177
     */
178
    public function up(Application $app, Request $request, $productClassId)
179
    {
180
        $this->isTokenValid($app);
181
182
        // FRONT_CART_UP_INITIALIZE
183
        $event = new EventArgs(
184
            array(
185
                'productClassId' => $productClassId,
186
            ),
187
            $request
188
        );
189
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_INITIALIZE, $event);
190
191
        try {
192
193
            log_info('カート加算処理開始', array('product_class_id' => $productClassId));
194
195
            $productClassId = $event->getArgument('productClassId');
196
197
            $app['eccube.service.cart']->upProductQuantity($productClassId)->save();
198
199
            // FRONT_CART_UP_COMPLETE
200
            $event = new EventArgs(
201
                array(
202
                    'productClassId' => $productClassId,
203
                ),
204
                $request
205
            );
206
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_COMPLETE, $event);
207
208
            if ($event->hasResponse()) {
209
                return $event->getResponse();
210
            }
211
212
            log_info('カート加算処理完了', array('product_class_id' => $productClassId));
213
214
        } catch (CartException $e) {
215
216
            log_info('カート加算エラー', array($e->getMessage()));
217
218
            // FRONT_CART_UP_EXCEPTION
219
            $event = new EventArgs(
220
                array(
221
                    'exception' => $e,
222
                ),
223
                $request
224
            );
225
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_EXCEPTION, $event);
226
227
            if ($event->hasResponse()) {
228
                return $event->getResponse();
229
            }
230
231
            $app->addRequestError($e->getMessage());
232
        }
233
234
        return $app->redirect($app->url('cart'));
235
    }
236
237
    /**
238
     * カートに入っている商品の個数を1減らす.
@@ 246-301 (lines=56) @@
243
     * @param $productClassId
244
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
245
     */
246
    public function down(Application $app, Request $request, $productClassId)
247
    {
248
        $this->isTokenValid($app);
249
250
        // FRONT_CART_DOWN_INITIALIZE
251
        $event = new EventArgs(
252
            array(
253
                'productClassId' => $productClassId,
254
            ),
255
            $request
256
        );
257
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_INITIALIZE, $event);
258
259
        try {
260
261
            log_info('カート減算処理開始', array('product_class_id' => $productClassId));
262
263
            $productClassId = $event->getArgument('productClassId');
264
            $app['eccube.service.cart']->downProductQuantity($productClassId)->save();
265
266
            // FRONT_CART_UP_COMPLETE
267
            $event = new EventArgs(
268
                array(
269
                    'productClassId' => $productClassId,
270
                ),
271
                $request
272
            );
273
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_COMPLETE, $event);
274
275
            if ($event->hasResponse()) {
276
                return $event->getResponse();
277
            }
278
279
            log_info('カート減算処理完了', array('product_class_id' => $productClassId));
280
281
        } catch (CartException $e) {
282
            log_info('カート減算エラー', array($e->getMessage()));
283
284
            // FRONT_CART_DOWN_EXCEPTION
285
            $event = new EventArgs(
286
                array(
287
                    'exception' => $e,
288
                ),
289
                $request
290
            );
291
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_EXCEPTION, $event);
292
293
            if ($event->hasResponse()) {
294
                return $event->getResponse();
295
            }
296
297
            $app->addRequestError($e->getMessage());
298
        }
299
300
        return $app->redirect($app->url('cart'));
301
    }
302
303
    /**
304
     * カートに入っている商品を削除する.
@@ 355-412 (lines=58) @@
352
     * @param $cart_no
353
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
354
     */
355
    public function upCartNo(Application $app, Request $request, $cart_no)
356
    {
357
        $this->isTokenValid($app);
358
359
        // FRONT_CART_UP_INITIALIZE
360
        $event = new EventArgs(
361
            array(
362
                'cart_no' => $cart_no,
363
            ),
364
            $request
365
        );
366
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_CART_NO_INITIALIZE, $event);
367
368
        try {
369
370
            log_info('カート加算処理開始', array('cart_no' => $cart_no));
371
372
            $cart_no = $event->getArgument('cart_no');
373
374
            $app['eccube.service.cart']->upCartNoQuantity($cart_no)->save();
375
376
            // FRONT_CART_UP_COMPLETE
377
            $event = new EventArgs(
378
                array(
379
                    'cart_no' => $cart_no,
380
                ),
381
                $request
382
            );
383
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_CART_NO_COMPLETE, $event);
384
385
            if ($event->hasResponse()) {
386
                return $event->getResponse();
387
            }
388
389
            log_info('カート加算処理完了', array('cart_no' => $cart_no));
390
391
        } catch (CartException $e) {
392
393
            log_info('カート加算エラー', array($e->getMessage()));
394
395
            // FRONT_CART_UP_EXCEPTION
396
            $event = new EventArgs(
397
                array(
398
                    'exception' => $e,
399
                ),
400
                $request
401
            );
402
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_UP_CART_NO_EXCEPTION, $event);
403
404
            if ($event->hasResponse()) {
405
                return $event->getResponse();
406
            }
407
408
            $app->addRequestError($e->getMessage());
409
        }
410
411
        return $app->redirect($app->url('cart'));
412
    }
413
414
    /**
415
     * カートに入っている商品の個数を1減らす.
@@ 422-479 (lines=58) @@
419
     * @param $cart_no
420
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
421
     */
422
    public function downCartNo(Application $app, Request $request, $cart_no)
423
    {
424
        $this->isTokenValid($app);
425
426
        // FRONT_CART_DOWN_INITIALIZE
427
        $event = new EventArgs(
428
            array(
429
                'cart_no' => $cart_no,
430
            ),
431
            $request
432
        );
433
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_CART_NO_INITIALIZE, $event);
434
435
        try {
436
437
            log_info('カート減算処理開始', array('cart_no' => $cart_no));
438
439
            $cart_no = $event->getArgument('cart_no');
440
441
            $app['eccube.service.cart']->downCartNoQuantity($cart_no)->save();
442
443
            // FRONT_CART_DOWN_COMPLETE
444
            $event = new EventArgs(
445
                array(
446
                    'cart_no' => $cart_no,
447
                ),
448
                $request
449
            );
450
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_CART_NO_COMPLETE, $event);
451
452
            if ($event->hasResponse()) {
453
                return $event->getResponse();
454
            }
455
456
            log_info('カート減算処理完了', array('cart_no' => $cart_no));
457
458
        } catch (CartException $e) {
459
460
            log_info('カート減算エラー', array($e->getMessage()));
461
462
            // FRONT_CART_DOWN_EXCEPTION
463
            $event = new EventArgs(
464
                array(
465
                    'exception' => $e,
466
                ),
467
                $request
468
            );
469
            $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CART_DOWN_CART_NO_EXCEPTION, $event);
470
471
            if ($event->hasResponse()) {
472
                return $event->getResponse();
473
            }
474
475
            $app->addRequestError($e->getMessage());
476
        }
477
478
        return $app->redirect($app->url('cart'));
479
    }
480
481
    /**
482
     * カートに入っている商品を削除する.