Completed
Pull Request — experimental/3.1 (#2154)
by Kentaro
448:33 queued 441:10
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\Order;
6
use Eccube\Entity\OrderDetail;
7
use Eccube\Service\Calculator\OrderDetailCollection;
8
9
class ShippingStrategy implements CalculateStrategyInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
10
{
11
    protected $app;
12
    protected $Order;
13
14 12
    public function __construct(Application $app = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
15
    {
16 12
        $this->app = $app;
17
    }
18
19 12
    public function execute(OrderDetailCollection $OrderDetails)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
20
    {
21
        // 送料をすべて足す
22 12
        $delivery_fee_total = array_reduce(
23
            array_map(
24
                function ($Shipping) {
25 12
                    return $Shipping->getShippingDeliveryFee();
26 12
                },
27 12
                $this->Order->getShippings()->toArray()
28
            ),
29 12
            function ($carry, $item) {
30 12
                return $carry += $item;
31 12
            }
32
        );
33
34
        // 送料が存在しない場合は追加
35 12
        if (!$OrderDetails->hasProductByName('送料')) {
36 12
            $OrderDetail = new OrderDetail();
37 12
            $OrderDetail->setProductName("送料")
38 12
                ->setPrice($delivery_fee_total)
39 12
                ->setPriceIncTax($delivery_fee_total)
40 12
                ->setTaxRate(0)
41 12
                ->setQuantity(1);
42 12
            $this->Order->setDeliveryFeeTotal($delivery_fee_total);
43 12
            $OrderDetails->append($OrderDetail);
44
        }
45
    }
46
47 12
    public function setApplication(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
48
    {
49 12
        $this->app = $app;
50 12
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
51
    }
52
53 12
    public function setOrder(Order $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
54
    {
55 12
        $this->Order = $Order;
56 12
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
57
    }
58
}
59