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

UpdateDatePurchaseProcessor   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 56
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 14
loc 56
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D process() 14 43 10

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\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