Failed Conditions
Push — experimental/3.1 ( 965511...751c7a )
by chihiro
21s
created

UpdateDatePurchaseProcessor::process()   D

Complexity

Conditions 10
Paths 9

Size

Total Lines 43
Code Lines 22

Duplication

Lines 14
Ratio 32.56 %

Importance

Changes 0
Metric Value
cc 10
eloc 22
nc 9
nop 2
dl 14
loc 43
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Eccube\Service\PurchaseFlow\Processor;
4
5
use Eccube\Entity\ItemHolderInterface;
6
use Eccube\Service\PurchaseFlow\PurchaseProcessor;
7
use Eccube\Service\PurchaseFlow\PurchaseContext;
8
9
/**
10
 * 受注情報の日付更新.
11
 */
12
class UpdateDatePurchaseProcessor implements PurchaseProcessor
13
{
14
    protected $app;
15
16
    public function __construct($app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
17
    {
18
        $this->app = $app;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function process(ItemHolderInterface $TargetOrder, PurchaseContext $context)
25
    {
26
        $dateTime = new \DateTime();
27
        $OriginOrder = $context->getOriginHolder();
28
29
        // 編集
30
        if ($TargetOrder->getId()) {
31
            // 発送済
32
            if ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_deliv']) {
33
                // 編集前と異なる場合のみ更新
34 View Code Duplication
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
35
                    $TargetOrder->setCommitDate($dateTime);
36
                    // お届け先情報の発送日も更新する.
37
                    $Shippings = $TargetOrder->getShippings();
38
                    foreach ($Shippings as $Shipping) {
39
                        $Shipping->setShippingCommitDate($dateTime);
40
                    }
41
                }
42
                // 入金済
43 View Code Duplication
            } elseif ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_pre_end']) {
44
                // 編集前と異なる場合のみ更新
45
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
46
                    $TargetOrder->setPaymentDate($dateTime);
47
                }
48
            }
49
            // 新規
50
        } else {
51
            // 発送済
52
            if ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_deliv']) {
53
                $TargetOrder->setCommitDate($dateTime);
54
                // お届け先情報の発送日も更新する.
55
                $Shippings = $TargetOrder->getShippings();
56
                foreach ($Shippings as $Shipping) {
57
                    $Shipping->setShippingCommitDate($dateTime);
58
                }
59
                // 入金済
60
            } elseif ($TargetOrder->getOrderStatus()->getId() == $this->app['config']['order_pre_end']) {
61
                $TargetOrder->setPaymentDate($dateTime);
62
            }
63
            // 受注日時
64
            $TargetOrder->setOrderDate($dateTime);
65
        }
66
    }
67
}
68