Failed Conditions
Pull Request — experimental/3.1 (#2449)
by Kiyotaka
52:40
created

ShippingStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 24.56 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 14
loc 57
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 14 28 3
A setApplication() 0 5 1
A setOrder() 0 5 1
A getTargetTypes() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

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:

1
<?php
2
namespace Eccube\Service\Calculator\Strategy;
3
4
use Eccube\Application;
5
use Eccube\Entity\Master\OrderItemType;
6
use Eccube\Entity\Master\TaxType;
7
use Eccube\Entity\Master\TaxDisplayType;
8
use Eccube\Entity\Order;
9
use Eccube\Entity\PurchaseInterface;
10
use Eccube\Entity\ShipmentItem;
11
use Eccube\Entity\Shipping;
12
use Eccube\Repository\Master\OrderItemTypeRepository;
13
use Eccube\Service\Calculator\ShipmentItemCollection;
14
15
class ShippingStrategy implements CalculateStrategyInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
16
{
17
    /* @var Application $app */
18
    protected $app;
19
20
    /* @var Order $Order */
21
    protected $Order;
22
23
    /** @var OrderItemTypeRepository */
24
    protected $OrderItemTypeRepository;
25
26
    public function execute(ShipmentItemCollection $ShipmentItems)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
27
    {
28
        // 送料の受注明細区分
29
        $DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE);
30
        // TODO
31
        $TaxInclude = $this->app['orm.em']->getRepository(TaxDisplayType::class)->find(TaxDisplayType::INCLUDED);
32
        $Taxion = $this->app['orm.em']->getRepository(TaxType::class)->find(TaxType::TAXATION);
33
34
        // 配送ごとに送料の明細を作成
35
        foreach ($this->Order->getShippings() as $Shipping) {
36
            /* @var Shipping $Shipping */
37
            $sio = new ShipmentItemCollection($Shipping->getShipmentItems()->toArray());
38 View Code Duplication
            if (!$sio->hasItemByOrderItemType($DeliveryFeeType)) {
39
                $ShipmentItem = new ShipmentItem();
40
                $ShipmentItem->setProductName("送料")
41
                    ->setPrice($Shipping->getShippingDeliveryFee())
42
                    ->setPriceIncTax($Shipping->getShippingDeliveryFee())
43
                    ->setTaxRate(8)
44
                    ->setQuantity(1)
45
                    ->setOrderItemType($DeliveryFeeType)
46
                    ->setShipping($Shipping)
47
                    ->setTaxDisplayType($TaxInclude)
48
                    ->setTaxType($Taxion);
49
                $ShipmentItems->add($ShipmentItem);
50
                $Shipping->addShipmentItem($ShipmentItem);
51
            }
52
        }
53
    }
54
55
    public function setApplication(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
56
    {
57
        $this->app = $app;
58
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
59
    }
60
61
    public function setOrder(PurchaseInterface $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
62
    {
63
        $this->Order = $Order;
0 ignored issues
show
Documentation Bug introduced by
It seems like $Order of type object<Eccube\Entity\PurchaseInterface> is incompatible with the declared type object<Eccube\Entity\Order> of property $Order.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
65
    }
66
67
    public function getTargetTypes()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
68
    {
69
        return [Order::class];
70
    }
71
}
72