Failed Conditions
Push — sf/last-boss ( 53d963...58156b )
by Kiyotaka
09:54 queued 04:25
created

DeliveryFeeChangeValidator::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 2
dl 18
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service\PurchaseFlow\Processor;
15
16
use Eccube\Entity\ItemHolderInterface;
17
use Eccube\Entity\Order;
18
use Eccube\Service\PurchaseFlow\InvalidItemException;
19
use Eccube\Service\PurchaseFlow\ItemHolderPostValidator;
20
use Eccube\Service\PurchaseFlow\PurchaseContext;
21
22
/**
23
 * 送料明細の金額とdtb_delivery_feeに登録されている送料の差異を検知するバリデータ.
24
 */
25 View Code Duplication
class DeliveryFeeChangeValidator extends ItemHolderPostValidator
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...
26
{
27
    /**
28
     * @param ItemHolderInterface $itemHolder
29
     * @param PurchaseContext $context
30
     *
31
     * @throws InvalidItemException
32
     */
33
    protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $context)
34
    {
35
        if (!$itemHolder instanceof Order) {
36
            return;
37
        }
38
39
        /** @var Order $originHolder */
40
        $originHolder = $context->getOriginHolder();
41
42
        // 受注の生成直後はチェックしない.
43
        if (!$originHolder->getOrderNo()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $originHolder->getOrderNo() of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
44
            return;
45
        }
46
47
        if ($originHolder->getDeliveryFeeTotal() != $itemHolder->getDeliveryFeeTotal()) {
48
            $this->throwInvalidItemException('送料が更新されました。金額をご確認ください。', null, true);
49
        }
50
    }
51
}
52