Failed Conditions
Pull Request — experimental/3.1 (#2374)
by Kentaro
119:10 queued 111:16
created

CalculateTotalStrategy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 38
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 9 9 1
A setApplication() 5 5 1
A setOrder() 5 5 1
A getTargetTypes() 4 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\Cart;
9
use Eccube\Entity\Order;
10
use Eccube\Entity\PurchaseInterface;
11
use Eccube\Entity\ShipmentItem;
12
use Eccube\Entity\Shipping;
13
use Eccube\Repository\Master\OrderItemTypeRepository;
14
use Eccube\Service\Calculator\ShipmentItemCollection;
15
16
/**
17
 * 明細の合計を集計して Order にセットする.
18
 */
19 View Code Duplication
class CalculateTotalStrategy implements CalculateStrategyInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /* @var Application $app */
22
    protected $app;
23
24
    /* @var Order $Order */
25
    protected $Order;
26
27
    /** @var OrderItemTypeRepository */
28
    protected $OrderItemTypeRepository;
29
30
    public function execute(ShipmentItemCollection $ShipmentItems)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
31
    {
32
        $total = $ShipmentItems->reduce(
33
            function($total, $ShipmentItem) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
34
                return $total + $ShipmentItem->getPrice() * $ShipmentItem->getQuantity();
35
            }, 0
36
        );
37
        $this->Order->setTotal($total);
38
    }
39
40
    public function setApplication(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
41
    {
42
        $this->app = $app;
43
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
44
    }
45
46
    public function setOrder(PurchaseInterface $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
47
    {
48
        $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...
49
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
50
    }
51
52
    public function getTargetTypes()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
53
    {
54
        return [Order::class, Cart::class];
55
    }
56
}
57