Completed
Pull Request — experimental/3.1 (#2154)
by Kentaro
448:33 queued 441:10
created

CalculateContext   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 21
cts 24
cp 0.875
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCalculateStrategies() 0 4 1
A executeCalculator() 0 15 4
A calculateOrder() 0 13 2
A setCalculateStrategies() 0 4 1
A setOrder() 0 6 1
1
<?php
2
namespace Eccube\Service\Calculator;
3
4
use Eccube\Entity\Order;
5
use Eccube\Entity\OrderDetail;
6
7
class CalculateContext
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
8
{
9
    protected $Order;
10
    protected $OrderDetails = []; // Collection になってる?
11
12
    // $app['eccube.calculate.strategies'] に DI する
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
13
    protected $CalculateStrategies;
14
15 12
    public function executeCalculator()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
16
    {
17 12
        foreach ($this->CalculateStrategies as $Strategy) {
18 12
            $Strategy->execute($this->OrderDetails);
19
        }
20
21 12
        foreach($this->OrderDetails as $OrderDetail) {
22 12
            if (!$this->Order->getOrderDetails()->contains($OrderDetail)) {
23 12
                $OrderDetail->setOrder($this->Order);
24 12
                $this->Order->addOrderDetail($OrderDetail);
25
                // ここのタイミングで Persist 可能?
26
            }
27
        }
28 12
        return $this->calculateOrder($this->Order);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
29
    }
30
31 12
    public function calculateOrder(Order $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
32
    {
33
        // OrderDetails の計算結果を Order にセットする
34 12
        $subTotal = $Order->calculateSubTotal();
35 12
        $Order->setSubtotal($subTotal);
36 12
        $total = $Order->getTotalPrice();
37 12
        if ($total < 0) {
38
            $total = 0;
39
        }
40 12
        $Order->setTotal($total);
41 12
        $Order->setPaymentTotal($total);
42 12
        return $Order;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
43
    }
44
45 12
    public function setCalculateStrategies(\Doctrine\Common\Collections\ArrayCollection $strategies)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
46
    {
47 12
        $this->CalculateStrategies = $strategies;
48
    }
49
50
    public function getCalculateStrategies()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
51
    {
52
        return $this->CalculateStrategies;
53
    }
54
55 12
    public function setOrder(Order $Order)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
56
    {
57 12
        $this->Order = $Order;
58
        // ArrayIterator のラップしたクラスを作って明細種別ごとに管理したい
59 12
        $this->OrderDetails = new OrderDetailCollection($Order->getOrderDetails()->toArray());
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Eccube\Service\Calc...erDetails()->toArray()) of type object<Eccube\Service\Ca...\OrderDetailCollection> is incompatible with the declared type array of property $OrderDetails.

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...
60
    }
61
}
62