Failed Conditions
Push — experimental/3.1 ( 0c67c0...62371a )
by chihiro
51:52
created

ShippingStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
namespace Eccube\Service\Calculator\Strategy;
3
4
use Eccube\Application;
5
use Eccube\Entity\Master\OrderItemType;
6
use Eccube\Entity\Order;
7
use Eccube\Entity\ShipmentItem;
8
use Eccube\Entity\Shipping;
9
use Eccube\Repository\Master\OrderItemTypeRepository;
10
use Eccube\Service\Calculator\ShipmentItemCollection;
11
12
class ShippingStrategy implements CalculateStrategyInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
13
{
14 12
    /* @var Application $app */
15
    protected $app;
16 12
17
    /* @var Order $Order */
18
    protected $Order;
19 12
20
    /** @var OrderItemTypeRepository */
21
    protected $OrderItemTypeRepository;
22 12
23
    public function execute(ShipmentItemCollection $ShipmentItems)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
24
    {
25 12
        // 送料の受注明細区分
26 12
        $DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE);
27 12
28
        // 配送ごとに送料の明細を作成
29 12
        foreach ($this->Order->getShippings() as $Shipping) {
30 12
            /* @var Shipping $Shipping */
31 12
            $sio = new ShipmentItemCollection($Shipping->getShipmentItems()->toArray());
32
            if (!$sio->hasItemByOrderItemType($DeliveryFeeType)) {
33
                $ShipmentItem = new ShipmentItem();
34
                $ShipmentItem->setProductName("送料")
35 12
                    ->setPrice($Shipping->getShippingDeliveryFee())
36 12
                    ->setPriceIncTax($Shipping->getShippingDeliveryFee())
37 12
                    ->setTaxRate(0)
38 12
                    ->setQuantity(1)
39 12
                    ->setOrderItemType($DeliveryFeeType)
40 12
                    ->setShipping($Shipping);
41 12
                $ShipmentItems->append($ShipmentItem);
42 12
                $Shipping->addShipmentItem($ShipmentItem);
43 12
            }
44
        }
45
46
        // 合計送料の計算
47 12
        $deliveryFeeTotal = array_reduce($ShipmentItems->getDeliveryFees()->getArrayCopy(), function($total, $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
48
            /* @var ShipmentItem $ShipmentItem */
49 12
            return $total + $ShipmentItem->getPriceIncTax();
50 12
        }, 0);
51
        $this->Order->setDeliveryFeeTotal($deliveryFeeTotal);
52
    }
53 12
54
    public function setApplication(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
55 12
    {
56 12
        $this->app = $app;
57
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
58
    }
59
60
    public function setOrder(Order $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
61
    {
62
        $this->Order = $Order;
63
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
64
    }
65
}
66