Completed
Pull Request — experimental/sf (#3307)
by k-yamamura
185:20 queued 177:36
created

CartController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Test Coverage

Coverage 85.19%

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
ccs 23
cts 27
cp 0.8519
wmc 4
lcom 2
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 36 2
A execPurchaseFlow() 0 9 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\Block;
15
16
use Eccube\Controller\AbstractController;
17
use Eccube\Entity\Cart;
18
use Eccube\Service\CartService;
19
use Eccube\Service\PurchaseFlow\PurchaseContext;
20
use Eccube\Service\PurchaseFlow\PurchaseFlow;
21
use Eccube\Service\PurchaseFlow\PurchaseFlowResult;
22
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
23
use Symfony\Component\HttpFoundation\Request;
24
25
class CartController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
26
{
27
    /**
28
     * @var CartService
29
     */
30
    protected $cartService;
31
32
    /**
33
     * @var PurchaseFlow
34
     */
35
    protected $purchaseFlow;
36
37 114
    public function __construct(
38
        CartService $cartService,
39
        PurchaseFlow $cartPurchaseFlow
40
    ) {
41 114
        $this->cartService = $cartService;
42 114
        $this->purchaseFlow = $cartPurchaseFlow;
43
    }
44
45
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$request" missing
Loading history...
46
     * @Route("/block/cart", name="block_cart")
47
     * @Route("/block/cart_sp", name="block_cart_sp")
48
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
49 114
    public function index(Request $request)
50
    {
51 114
        $Carts = $this->cartService->getCarts();
52
53
        // 二重に実行され, 注文画面でのエラーハンドリングができないので
54
        // ここではpurchaseFlowは実行しない
55
56 114
        $totalQuantity = array_reduce($Carts, function ($total, $Cart) {
57
            /* @var Cart $Cart */
58 71
            $total += $Cart->getTotalQuantity();
59
60 71
            return $total;
61 114
        }, 0);
62 114
        $totalPrice = array_reduce($Carts, function ($total, $Cart) {
63
            /* @var Cart $Cart */
64 71
            $total += $Cart->getTotalPrice();
65
66 71
            return $total;
67 114
        }, 0);
68
69 114
        $route = $request->attributes->get('_route');
70
71 114
        if ($route == 'block_cart_sp') {
72 113
            return $this->render('Block/nav_sp.twig', [
73 113
                'totalQuantity' => $totalQuantity,
74 113
                'totalPrice' => $totalPrice,
75 113
                'Carts' => $Carts,
76
            ]);
77
        } else {
78 114
            return $this->render('Block/cart.twig', [
79 114
                'totalQuantity' => $totalQuantity,
80 114
                'totalPrice' => $totalPrice,
81 114
                'Carts' => $Carts,
82
            ]);
83
        }
84
    }
85
86
    protected function execPurchaseFlow($Carts)
87
    {
88
        /** @var PurchaseFlowResult[] $flowResults */
89
        $flowResults = array_map(function ($Cart) {
0 ignored issues
show
Unused Code introduced by
$flowResults is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
90
            $purchaseContext = new PurchaseContext($Cart, $this->getUser());
91
92
            return $this->purchaseFlow->validate($Cart, $purchaseContext);
93
        }, $Carts);
94
    }
95
}
96