Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ProductController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProductController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 59 | class ProductController extends AbstractController |
||
| 60 | { |
||
| 61 | /** |
||
| 62 | * @var CsvExportService |
||
| 63 | */ |
||
| 64 | protected $csvExportService; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var ProductClassRepository |
||
| 68 | */ |
||
| 69 | protected $productClassRepository; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var ProductImageRepository |
||
| 73 | */ |
||
| 74 | protected $productImageRepository; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var TaxRuleRepository |
||
| 78 | */ |
||
| 79 | protected $taxRuleRepository; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var CategoryRepository |
||
| 83 | */ |
||
| 84 | protected $categoryRepository; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var ProductRepository |
||
| 88 | */ |
||
| 89 | protected $productRepository; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var BaseInfo |
||
| 93 | */ |
||
| 94 | protected $BaseInfo; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var PageMaxRepository |
||
| 98 | */ |
||
| 99 | protected $pageMaxRepository; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var ProductStatusRepository |
||
| 103 | */ |
||
| 104 | protected $productStatusRepository; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var TagRepository |
||
| 108 | */ |
||
| 109 | protected $tagRepository; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * ProductController constructor. |
||
| 113 | * |
||
| 114 | * @param CsvExportService $csvExportService |
||
| 115 | * @param ProductClassRepository $productClassRepository |
||
| 116 | * @param ProductImageRepository $productImageRepository |
||
| 117 | * @param TaxRuleRepository $taxRuleRepository |
||
| 118 | * @param CategoryRepository $categoryRepository |
||
| 119 | * @param ProductRepository $productRepository |
||
| 120 | * @param BaseInfoRepository $baseInfoRepository |
||
| 121 | * @param PageMaxRepository $pageMaxRepository |
||
| 122 | * @param ProductStatusRepository $productStatusRepository |
||
| 123 | * @param TagRepository $tagRepository |
||
| 124 | 26 | */ |
|
| 125 | View Code Duplication | public function __construct( |
|
| 148 | |||
| 149 | /** |
||
| 150 | * @Route("/%eccube_admin_route%/product", name="admin_product") |
||
| 151 | * @Route("/%eccube_admin_route%/product/page/{page_no}", requirements={"page_no" = "\d+"}, name="admin_product_page") |
||
| 152 | * @Template("@admin/Product/index.twig") |
||
| 153 | 4 | */ |
|
| 154 | public function index(Request $request, $page_no = null, Paginator $paginator) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @Route("/%eccube_admin_route%/product/classes/{id}/load", name="admin_product_classes_load", methods={"GET"}, requirements={"id" = "\d+"}) |
||
| 276 | * @Template("@admin/Product/product_class_popup.twig") |
||
| 277 | * @ParamConverter("Product", options={"repository_method":"findWithSortedClassCategories"}) |
||
| 278 | */ |
||
| 279 | 1 | public function loadProductClasses(Request $request, Product $Product) |
|
| 280 | { |
||
| 281 | 1 | if (!$request->isXmlHttpRequest()) { |
|
| 282 | throw new BadRequestHttpException(); |
||
| 283 | } |
||
| 284 | |||
| 285 | 1 | $data = []; |
|
| 286 | /** @var $Product ProductRepository */ |
||
| 287 | 1 | if (!$Product) { |
|
| 288 | throw new NotFoundHttpException(); |
||
| 289 | } |
||
| 290 | |||
| 291 | 1 | if ($Product->hasProductClass()) { |
|
| 292 | 1 | $class = $Product->getProductClasses(); |
|
| 293 | 1 | foreach ($class as $item) { |
|
| 294 | 1 | $data[] = $item; |
|
| 295 | 1 | } |
|
| 296 | } |
||
| 297 | |||
| 298 | return [ |
||
| 299 | 'data' => $data, |
||
| 300 | ]; |
||
| 301 | 1 | } |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @Route("/%eccube_admin_route%/product/product/image/add", name="admin_product_image_add", methods={"POST"}) |
||
| 305 | */ |
||
| 306 | public function addImage(Request $request) |
||
| 307 | { |
||
| 308 | if (!$request->isXmlHttpRequest()) { |
||
| 309 | throw new BadRequestHttpException(); |
||
| 310 | } |
||
| 311 | |||
| 312 | $images = $request->files->get('admin_product'); |
||
| 313 | |||
| 314 | $allowExtensions = ['gif', 'jpg', 'jpeg', 'png']; |
||
| 315 | $files = []; |
||
| 316 | if (count($images) > 0) { |
||
| 317 | foreach ($images as $img) { |
||
| 318 | foreach ($img as $image) { |
||
| 319 | //ファイルフォーマット検証 |
||
| 320 | $mimeType = $image->getMimeType(); |
||
| 321 | if (0 !== strpos($mimeType, 'image')) { |
||
| 322 | throw new UnsupportedMediaTypeHttpException(); |
||
| 323 | } |
||
| 324 | |||
| 325 | // 拡張子 |
||
| 326 | $extension = $image->getClientOriginalExtension(); |
||
| 327 | if (!in_array(strtolower($extension), $allowExtensions)) { |
||
| 328 | throw new UnsupportedMediaTypeHttpException(); |
||
| 329 | } |
||
| 330 | |||
| 331 | $filename = date('mdHis').uniqid('_').'.'.$extension; |
||
| 332 | $image->move($this->eccubeConfig['eccube_temp_image_dir'], $filename); |
||
| 333 | $files[] = $filename; |
||
| 334 | } |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | $event = new EventArgs( |
||
| 339 | [ |
||
| 340 | 'images' => $images, |
||
| 341 | 'files' => $files, |
||
| 342 | ], |
||
| 343 | $request |
||
| 344 | ); |
||
| 345 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_ADD_IMAGE_COMPLETE, $event); |
||
| 346 | $files = $event->getArgument('files'); |
||
| 347 | |||
| 348 | return $this->json(['files' => $files], 200); |
||
| 349 | } |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @Route("/%eccube_admin_route%/product/product/new", name="admin_product_product_new") |
||
| 353 | 18 | * @Route("/%eccube_admin_route%/product/product/{id}/edit", requirements={"id" = "\d+"}, name="admin_product_product_edit") |
|
| 354 | * @Template("@admin/Product/product.twig") |
||
| 355 | 18 | */ |
|
| 356 | 18 | public function edit(Request $request, $id = null, RouterInterface $router, CacheUtil $cacheUtil) |
|
| 357 | 5 | { |
|
| 358 | 5 | $has_class = false; |
|
| 359 | 5 | if (is_null($id)) { |
|
| 360 | $Product = new Product(); |
||
| 361 | 5 | $ProductClass = new ProductClass(); |
|
| 362 | 5 | $ProductStatus = $this->productStatusRepository->find(ProductStatus::DISPLAY_HIDE); |
|
| 363 | $Product |
||
| 364 | 5 | ->addProductClass($ProductClass) |
|
| 365 | 5 | ->setStatus($ProductStatus); |
|
| 366 | 5 | $ProductClass |
|
| 367 | 5 | ->setVisible(true) |
|
| 368 | 5 | ->setStockUnlimited(true) |
|
| 369 | 5 | ->setProduct($Product); |
|
| 370 | $ProductStock = new ProductStock(); |
||
| 371 | 13 | $ProductClass->setProductStock($ProductStock); |
|
| 372 | 13 | $ProductStock->setProductClass($ProductClass); |
|
| 373 | } else { |
||
| 374 | $Product = $this->productRepository->findWithSortedClassCategories($id); |
||
| 375 | $ProductClass = null; |
||
| 376 | 13 | $ProductStock = null; |
|
| 377 | 13 | if (!$Product) { |
|
| 378 | 11 | throw new NotFoundHttpException(); |
|
| 379 | 11 | } |
|
| 380 | 11 | // 規格無しの商品の場合は、デフォルト規格を表示用に取得する |
|
| 381 | $has_class = $Product->hasProductClass(); |
||
| 382 | if (!$has_class) { |
||
| 383 | 11 | $ProductClasses = $Product->getProductClasses(); |
|
| 384 | 11 | foreach ($ProductClasses as $pc) { |
|
| 385 | 11 | if (!is_null($pc->getClassCategory1())) { |
|
| 386 | continue; |
||
| 387 | } |
||
| 388 | 11 | if ($pc->isVisible()) { |
|
| 389 | 6 | $ProductClass = $pc; |
|
| 390 | break; |
||
| 391 | 11 | } |
|
| 392 | } |
||
| 393 | if ($this->BaseInfo->isOptionProductTaxRule() && $ProductClass->getTaxRule()) { |
||
| 394 | $ProductClass->setTaxRate($ProductClass->getTaxRule()->getTaxRate()); |
||
| 395 | 18 | } |
|
| 396 | 18 | $ProductStock = $ProductClass->getProductStock(); |
|
| 397 | } |
||
| 398 | } |
||
| 399 | 18 | ||
| 400 | 2 | $builder = $this->formFactory |
|
| 401 | ->createBuilder(ProductType::class, $Product); |
||
| 402 | |||
| 403 | 18 | // 規格あり商品の場合、規格関連情報をFormから除外 |
|
| 404 | if ($has_class) { |
||
| 405 | 18 | $builder->remove('class'); |
|
| 406 | 18 | } |
|
| 407 | |||
| 408 | 18 | $event = new EventArgs( |
|
| 409 | [ |
||
| 410 | 18 | 'builder' => $builder, |
|
| 411 | 'Product' => $Product, |
||
| 412 | 18 | ], |
|
| 413 | $request |
||
| 414 | 18 | ); |
|
| 415 | 16 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_INITIALIZE, $event); |
|
| 416 | 16 | ||
| 417 | $form = $builder->getForm(); |
||
| 418 | |||
| 419 | if (!$has_class) { |
||
| 420 | 18 | $ProductClass->setStockUnlimited($ProductClass->isStockUnlimited()); |
|
| 421 | 18 | $form['class']->setData($ProductClass); |
|
| 422 | 18 | } |
|
| 423 | 13 | ||
| 424 | // ファイルの登録 |
||
| 425 | 18 | $images = []; |
|
| 426 | $ProductImages = $Product->getProductImage(); |
||
| 427 | 18 | foreach ($ProductImages as $ProductImage) { |
|
| 428 | 18 | $images[] = $ProductImage->getFileName(); |
|
| 429 | 18 | } |
|
| 430 | $form['images']->setData($images); |
||
| 431 | 13 | ||
| 432 | $categories = []; |
||
| 433 | 18 | $ProductCategories = $Product->getProductCategories(); |
|
| 434 | foreach ($ProductCategories as $ProductCategory) { |
||
| 435 | 18 | /* @var $ProductCategory \Eccube\Entity\ProductCategory */ |
|
| 436 | 18 | $categories[] = $ProductCategory->getCategory(); |
|
| 437 | } |
||
| 438 | 18 | $form['Category']->setData($categories); |
|
| 439 | 13 | ||
| 440 | 13 | $Tags = $Product->getTags(); |
|
| 441 | 13 | $form['Tag']->setData($Tags); |
|
| 442 | 13 | ||
| 443 | if ('POST' === $request->getMethod()) { |
||
| 444 | 13 | $form->handleRequest($request); |
|
| 445 | 13 | if ($form->isValid()) { |
|
| 446 | log_info('商品登録開始', [$id]); |
||
| 447 | $Product = $form->getData(); |
||
| 448 | 13 | ||
| 449 | 12 | if (!$has_class) { |
|
| 450 | 8 | $ProductClass = $form['class']->getData(); |
|
| 451 | 4 | ||
| 452 | // 個別消費税 |
||
| 453 | 4 | if ($this->BaseInfo->isOptionProductTaxRule()) { |
|
| 454 | 4 | if ($ProductClass->getTaxRate() !== null) { |
|
| 455 | 4 | if ($ProductClass->getTaxRule()) { |
|
| 456 | 4 | $ProductClass->getTaxRule()->setTaxRate($ProductClass->getTaxRate()); |
|
| 457 | 4 | } else { |
|
| 458 | 4 | $taxrule = $this->taxRuleRepository->newTaxRule(); |
|
| 459 | $taxrule->setTaxRate($ProductClass->getTaxRate()); |
||
| 460 | $taxrule->setApplyDate(new \DateTime()); |
||
| 461 | 8 | $taxrule->setProduct($Product); |
|
| 462 | $taxrule->setProductClass($ProductClass); |
||
| 463 | 4 | $ProductClass->setTaxRule($taxrule); |
|
| 464 | 2 | } |
|
| 465 | 2 | ||
| 466 | $ProductClass->getTaxRule()->setTaxRate($ProductClass->getTaxRate()); |
||
| 467 | } else { |
||
| 468 | if ($ProductClass->getTaxRule()) { |
||
| 469 | 13 | $this->taxRuleRepository->delete($ProductClass->getTaxRule()); |
|
| 470 | $ProductClass->setTaxRule(null); |
||
| 471 | } |
||
| 472 | 13 | } |
|
| 473 | } |
||
| 474 | $this->entityManager->persist($ProductClass); |
||
| 475 | |||
| 476 | 13 | // 在庫情報を作成 |
|
| 477 | if (!$ProductClass->isStockUnlimited()) { |
||
| 478 | 13 | $ProductStock->setStock($ProductClass->getStock()); |
|
| 479 | } else { |
||
| 480 | // 在庫無制限時はnullを設定 |
||
| 481 | $ProductStock->setStock(null); |
||
| 482 | } |
||
| 483 | $this->entityManager->persist($ProductStock); |
||
| 484 | 13 | } |
|
| 485 | 10 | ||
| 486 | 10 | // カテゴリの登録 |
|
| 487 | // 一度クリア |
||
| 488 | 13 | /* @var $Product \Eccube\Entity\Product */ |
|
| 489 | 13 | foreach ($Product->getProductCategories() as $ProductCategory) { |
|
| 490 | $Product->removeProductCategory($ProductCategory); |
||
| 491 | 13 | $this->entityManager->remove($ProductCategory); |
|
| 492 | 13 | } |
|
| 493 | 13 | $this->entityManager->persist($Product); |
|
| 494 | 13 | $this->entityManager->flush(); |
|
| 495 | |||
| 496 | $count = 1; |
||
| 497 | $Categories = $form->get('Category')->getData(); |
||
| 498 | $categoriesIdList = []; |
||
| 499 | foreach ($Categories as $Category) { |
||
| 500 | View Code Duplication | foreach ($Category->getPath() as $ParentCategory) { |
|
| 501 | if (!isset($categoriesIdList[$ParentCategory->getId()])) { |
||
| 502 | $ProductCategory = $this->createProductCategory($Product, $ParentCategory, $count); |
||
| 503 | $this->entityManager->persist($ProductCategory); |
||
| 504 | $count++; |
||
| 505 | /* @var $Product \Eccube\Entity\Product */ |
||
| 506 | $Product->addProductCategory($ProductCategory); |
||
| 507 | $categoriesIdList[$ParentCategory->getId()] = true; |
||
| 508 | } |
||
| 509 | } |
||
| 510 | if (!isset($categoriesIdList[$Category->getId()])) { |
||
| 511 | $ProductCategory = $this->createProductCategory($Product, $Category, $count); |
||
| 512 | $this->entityManager->persist($ProductCategory); |
||
| 513 | $count++; |
||
| 514 | /* @var $Product \Eccube\Entity\Product */ |
||
| 515 | $Product->addProductCategory($ProductCategory); |
||
| 516 | 13 | $categoriesIdList[$Category->getId()] = true; |
|
| 517 | 13 | } |
|
| 518 | } |
||
| 519 | |||
| 520 | // 画像の登録 |
||
| 521 | $add_images = $form->get('add_images')->getData(); |
||
| 522 | foreach ($add_images as $add_image) { |
||
| 523 | $ProductImage = new \Eccube\Entity\ProductImage(); |
||
| 524 | $ProductImage |
||
| 525 | ->setFileName($add_image) |
||
| 526 | ->setProduct($Product) |
||
| 527 | ->setSortNo(1); |
||
| 528 | $Product->addProductImage($ProductImage); |
||
| 529 | $this->entityManager->persist($ProductImage); |
||
| 530 | |||
| 531 | // 移動 |
||
| 532 | 13 | $file = new File($this->eccubeConfig['eccube_temp_image_dir'].'/'.$add_image); |
|
| 533 | 13 | $file->move($this->eccubeConfig['eccube_save_image_dir']); |
|
| 534 | } |
||
| 535 | |||
| 536 | // 画像の削除 |
||
| 537 | $delete_images = $form->get('delete_images')->getData(); |
||
| 538 | foreach ($delete_images as $delete_image) { |
||
| 539 | $ProductImage = $this->productImageRepository |
||
| 540 | ->findOneBy(['file_name' => $delete_image]); |
||
| 541 | |||
| 542 | // 追加してすぐに削除した画像は、Entityに追加されない |
||
| 543 | if ($ProductImage instanceof ProductImage) { |
||
| 544 | $Product->removeProductImage($ProductImage); |
||
| 545 | $this->entityManager->remove($ProductImage); |
||
| 546 | } |
||
| 547 | $this->entityManager->persist($Product); |
||
| 548 | 13 | $this->entityManager->flush(); |
|
| 549 | 13 | ||
| 550 | if (!$this->productImageRepository->findOneBy(['file_name' => $delete_image])) { |
||
| 551 | 13 | // 削除 |
|
| 552 | 13 | $fs = new Filesystem(); |
|
| 553 | $fs->remove($this->eccubeConfig['eccube_save_image_dir'] . '/' . $delete_image); |
||
| 554 | } |
||
| 555 | } |
||
| 556 | $this->entityManager->persist($Product); |
||
| 557 | $this->entityManager->flush(); |
||
| 558 | |||
| 559 | $sortNos = $request->get('sort_no_images'); |
||
| 560 | if ($sortNos) { |
||
| 561 | foreach ($sortNos as $sortNo) { |
||
| 562 | list($filename, $sortNo_val) = explode('//', $sortNo); |
||
| 563 | $ProductImage = $this->productImageRepository |
||
| 564 | 13 | ->findOneBy([ |
|
| 565 | 'file_name' => $filename, |
||
| 566 | 'Product' => $Product, |
||
| 567 | ]); |
||
| 568 | 13 | $ProductImage->setSortNo($sortNo_val); |
|
| 569 | 13 | $this->entityManager->persist($ProductImage); |
|
| 570 | 1 | } |
|
| 571 | 1 | } |
|
| 572 | $this->entityManager->flush(); |
||
| 573 | |||
| 574 | // 商品タグの登録 |
||
| 575 | 13 | // 商品タグを一度クリア |
|
| 576 | 13 | $ProductTags = $Product->getProductTag(); |
|
| 577 | 13 | foreach ($ProductTags as $ProductTag) { |
|
| 578 | $Product->removeProductTag($ProductTag); |
||
| 579 | 13 | $this->entityManager->remove($ProductTag); |
|
| 580 | 13 | } |
|
| 581 | 13 | ||
| 582 | 13 | // 商品タグの登録 |
|
| 583 | $Tags = $form->get('Tag')->getData(); |
||
| 584 | foreach ($Tags as $Tag) { |
||
| 585 | 13 | $ProductTag = new ProductTag(); |
|
| 586 | 13 | $ProductTag |
|
| 587 | ->setProduct($Product) |
||
| 588 | 13 | ->setTag($Tag); |
|
| 589 | $Product->addProductTag($ProductTag); |
||
| 590 | 13 | $this->entityManager->persist($ProductTag); |
|
| 591 | } |
||
| 592 | 13 | ||
| 593 | 13 | $Product->setUpdateDate(new \DateTime()); |
|
| 594 | $this->entityManager->flush(); |
||
| 595 | 13 | ||
| 596 | log_info('商品登録完了', [$id]); |
||
| 597 | 13 | ||
| 598 | $event = new EventArgs( |
||
| 599 | 13 | [ |
|
| 600 | 'form' => $form, |
||
| 601 | 13 | 'Product' => $Product, |
|
| 602 | 1 | ], |
|
| 603 | $request |
||
| 604 | ); |
||
| 605 | 13 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE, $event); |
|
| 606 | |||
| 607 | $this->addSuccess('admin.common.save_complete', 'admin'); |
||
| 608 | |||
| 609 | View Code Duplication | if ($returnLink = $form->get('return_link')->getData()) { |
|
| 610 | 5 | try { |
|
| 611 | 5 | // $returnLinkはpathの形式で渡される. pathが存在するかをルータでチェックする. |
|
| 612 | $pattern = '/^'.preg_quote($request->getBasePath(), '/').'/'; |
||
| 613 | 5 | $returnLink = preg_replace($pattern, '', $returnLink); |
|
| 614 | $result = $router->match($returnLink); |
||
| 615 | 5 | // パラメータのみ抽出 |
|
| 616 | 5 | $params = array_filter($result, function ($key) { |
|
| 617 | return 0 !== \strpos($key, '_'); |
||
| 618 | 5 | }, ARRAY_FILTER_USE_KEY); |
|
| 619 | |||
| 620 | 5 | // pathからurlを再構築してリダイレクト. |
|
| 621 | return $this->redirectToRoute($result['_route'], $params); |
||
| 622 | 5 | } catch (\Exception $e) { |
|
| 623 | // マッチしない場合はログ出力してスキップ. |
||
| 624 | 5 | log_warning('URLの形式が不正です。'); |
|
| 625 | } |
||
| 626 | } |
||
| 627 | |||
| 628 | $cacheUtil->clearDoctrineCache(); |
||
| 629 | 5 | ||
| 630 | return $this->redirectToRoute('admin_product_product_edit', ['id' => $Product->getId()]); |
||
| 631 | } |
||
| 632 | 5 | } |
|
| 633 | 5 | ||
| 634 | 3 | // 検索結果の保持 |
|
| 635 | 5 | $builder = $this->formFactory |
|
| 636 | ->createBuilder(SearchProductType::class); |
||
| 637 | |||
| 638 | 5 | $event = new EventArgs( |
|
| 639 | 5 | [ |
|
| 640 | 5 | 'builder' => $builder, |
|
| 641 | 5 | 'Product' => $Product, |
|
| 642 | 5 | ], |
|
| 643 | 5 | $request |
|
| 644 | 5 | ); |
|
| 645 | 5 | $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_PRODUCT_EDIT_SEARCH, $event); |
|
| 646 | 5 | ||
| 647 | $searchForm = $builder->getForm(); |
||
| 648 | |||
| 649 | if ('POST' === $request->getMethod()) { |
||
| 650 | $searchForm->handleRequest($request); |
||
| 651 | } |
||
| 652 | |||
| 653 | // Get Tags |
||
| 654 | 1 | $TagsList = $this->tagRepository->getList(); |
|
| 655 | |||
| 656 | 1 | // ツリー表示のため、ルートからのカテゴリを取得 |
|
| 657 | 1 | $TopCategories = $this->categoryRepository->getList(null); |
|
| 658 | 1 | $ChoicedCategoryIds = array_map(function ($Category) { |
|
| 659 | 1 | return $Category->getId(); |
|
| 660 | 1 | }, $form->get('Category')->getData()); |
|
| 661 | 1 | ||
| 662 | return [ |
||
| 663 | 1 | 'Product' => $Product, |
|
| 664 | 'Tags' => $Tags, |
||
| 665 | 1 | 'TagsList' => $TagsList, |
|
| 666 | 1 | 'form' => $form->createView(), |
|
| 667 | 'searchForm' => $searchForm->createView(), |
||
| 668 | 'has_class' => $has_class, |
||
| 669 | 'id' => $id, |
||
| 670 | 'TopCategories' => $TopCategories, |
||
| 671 | 'ChoicedCategoryIds' => $ChoicedCategoryIds, |
||
| 672 | ]; |
||
| 673 | } |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @Route("/%eccube_admin_route%/product/product/{id}/delete", requirements={"id" = "\d+"}, name="admin_product_product_delete", methods={"DELETE"}) |
||
| 677 | */ |
||
| 678 | public function delete(Request $request, $id = null, CacheUtil $cacheUtil) |
||
| 771 | 1 | ||
| 772 | 1 | /** |
|
| 773 | 1 | * @Route("/%eccube_admin_route%/product/product/{id}/copy", requirements={"id" = "\d+"}, name="admin_product_product_copy", methods={"POST"}) |
|
| 774 | */ |
||
| 775 | public function copy(Request $request, $id = null) |
||
| 871 | |||
| 872 | /** |
||
| 873 | * @Route("/%eccube_admin_route%/product/product/{id}/display", requirements={"id" = "\d+"}, name="admin_product_product_display") |
||
| 874 | */ |
||
| 875 | public function display(Request $request, $id = null) |
||
| 889 | |||
| 890 | /** |
||
| 891 | * 商品CSVの出力. |
||
| 892 | * |
||
| 893 | * @Route("/%eccube_admin_route%/product/export", name="admin_product_export") |
||
| 894 | * |
||
| 895 | * @param Request $request |
||
| 896 | * |
||
| 897 | * @return StreamedResponse |
||
| 898 | */ |
||
| 899 | public function export(Request $request) |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * ProductCategory作成 |
||
| 1003 | * |
||
| 1004 | 1 | * @param \Eccube\Entity\Product $Product |
|
| 1005 | * @param \Eccube\Entity\Category $Category |
||
| 1006 | 1 | * @param integer $count |
|
| 1007 | * |
||
| 1008 | * @return \Eccube\Entity\ProductCategory |
||
| 1009 | 1 | */ |
|
| 1010 | 1 | View Code Duplication | private function createProductCategory($Product, $Category, $count) |
| 1020 | |||
| 1021 | 1 | /** |
|
| 1022 | 1 | * Bulk public action |
|
| 1023 | 1 | * |
|
| 1024 | 1 | * @Route("/%eccube_admin_route%/product/bulk/product-status/{id}", requirements={"id" = "\d+"}, name="admin_product_bulk_product_status", methods={"POST"}) |
|
| 1025 | 1 | * |
|
| 1026 | * @param Request $request |
||
| 1027 | 1 | * @param ProductStatus $ProductStatus |
|
| 1028 | * |
||
| 1029 | * @return RedirectResponse |
||
| 1030 | */ |
||
| 1031 | public function bulkProductStatus(Request $request, ProductStatus $ProductStatus, CacheUtil $cacheUtil) |
||
| 1063 | } |
||
| 1064 |
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.