Failed Conditions
Branch experimental/sf (68db07)
by Kentaro
42:17 queued 33:39
created

CartController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
ccs 16
cts 20
cp 0.8
wmc 3
lcom 2
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 26 1
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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
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
    /**
46
     * @Route("/block/cart", name="block_cart")
47
     * @Template("Block/cart.twig")
48
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
49 114
    public function index()
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
        return [
70 114
            'totalQuantity' => $totalQuantity,
71 114
            'totalPrice' => $totalPrice,
72 114
            'Carts' => $Carts,
73
        ];
74
    }
75
76
    protected function execPurchaseFlow($Carts)
77
    {
78
        /** @var PurchaseFlowResult[] $flowResults */
79
        $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...
80
            $purchaseContext = new PurchaseContext($Cart, $this->getUser());
81
82
            return $this->purchaseFlow->calculate($Cart, $purchaseContext);
83
        }, $Carts);
84
    }
85
}
86