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

TaxStrategy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 13.16 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 5
loc 38
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 5 10 2
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
3
namespace Eccube\Service\Calculator\Strategy;
4
5
use Eccube\Application;
6
use Eccube\Entity\Order;
7
use Eccube\Entity\PurchaseInterface;
8
use Eccube\Entity\ShipmentItem;
9
use Eccube\Service\Calculator\ShipmentItemCollection;
10
11
class TaxStrategy implements CalculateStrategyInterface
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
12
{
13
    protected $app;
14
    protected $Order;
15
16
    public function __construct(Application $app = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
17
    {
18
        $this->app = $app;
19
    }
20
21
    public function execute(ShipmentItemCollection $ShipmentItems)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
22
    {
23
        // map でやりたい
24
        /* @var ShipmentItem $ShipmentItem */
25 View Code Duplication
        foreach ($ShipmentItems as $ShipmentItem) {
26
            $tax = $this->app['eccube.service.tax_rule']
27
                ->calcTax($ShipmentItem->getPrice(), $ShipmentItem->getTaxRate(), $ShipmentItem->getTaxRule());
28
            $ShipmentItem->setPriceIncTax($ShipmentItem->getPrice() + $tax);
29
        }
30
    }
31
32
    public function setApplication(Application $app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
33
    {
34
        $this->app = $app;
35
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
36
    }
37
38
    public function setOrder(PurchaseInterface $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
39
    {
40
        $this->Order = $Order;
41
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
42
    }
43
44
    public function getTargetTypes()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
45
    {
46
        return [Order::class];
47
    }
48
}
49