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

PaymentChargeChangeValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 18 18 4

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
/*
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
 * 手数料が変更されたかどうかを検知するバリデータ.
24
 */
25 View Code Duplication
class PaymentChargeChangeValidator 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->getCharge() != $itemHolder->getCharge()) {
48
            $this->throwInvalidItemException('手数料が更新されました。金額をご確認ください。', null, true);
49
        }
50
    }
51
}
52