Test Failed
Pull Request — feature/families (#15)
by Yuji
03:53
created

UpdateOrderStatusRequest   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 148
Duplicated Lines 39.86 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 5
dl 59
loc 148
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setSellerId() 10 10 2
A setOrderId() 10 10 2
A setIsPointFix() 10 10 3
A setOrderStatus() 9 9 2
A setOperationUser() 10 10 2
A setCancelReason() 10 10 2
A getParams() 0 9 1
B validateRequest() 0 19 7

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 Shippinno\YahooShoppingJp\Request;
4
5
use LogicException;
6
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException;
7
use Shippinno\YahooShoppingJp\Enum\OrderStatus;
8
use Shippinno\YahooShoppingJp\Enum\CancelReason;
9
use FluidXml\FluidXml;
10
11
class UpdateOrderStatusRequest extends AbstractRequest
12
{
13
    /**
14
     * @var array
15
     */
16
    private $params = [];
17
18
    /**
19
     * 【必須】ストアアカウント
20
     *
21
     * @param string $sellerId
22
     * @return self
23
     */
24 View Code Duplication
    public function setSellerId(string $sellerId): self
0 ignored issues
show
Duplication introduced by
This method 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...
25
    {
26
        if (isset($this->params['SellerId'])) {
27
            throw new LogicException('SellerId is already set.');
28
        }
29
30
        $this->params['SellerId'] = $sellerId;
31
32
        return $this;
33
    }
34
35
    /**
36
     * 【必須】注文ID
37
     *
38
     * @param string $orderId
39
     * @return self
40
     */
41 View Code Duplication
    public function setOrderId(string $orderId): self
0 ignored issues
show
Duplication introduced by
This method 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...
42
    {
43
        if (isset($this->params['Target']['OrderId'])) {
44
            throw new LogicException('OrderId is already set.');
45
        }
46
47
        $this->params['Target']['OrderId'] = $orderId;
48
49
        return $this;
50
    }
51
52
    /**
53
     * 【必須】ポイント確定要否
54
     * true : ポイント確定します。
55
     * false : ポイント確定しません。
56
     * ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
57
     *
58
     * @param bool $isPointFix
59
     * @return self
60
     */
61 View Code Duplication
    public function setIsPointFix(bool $isPointFix): self
0 ignored issues
show
Duplication introduced by
This method 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...
62
    {
63
        if (isset($this->params['Target']['IsPointFix'])) {
64
            throw new LogicException('IsPointFix is already set.');
65
        }
66
67
        $this->params['Target']['IsPointFix'] = ($isPointFix ? 'true' : 'false');
68
69
        return $this;
70
    }
71
72
    /**
73
     * 【必須】注文ステータス
74
     *
75
     * @param OrderStatus $orderStatus
76
     * @return self
77
     */
78 View Code Duplication
    public function setOrderStatus(OrderStatus $orderStatus): self
0 ignored issues
show
Duplication introduced by
This method 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...
79
    {
80
        if (isset($this->params['Order']['OrderStatus'])) {
81
            throw new LogicException('OrderStatus is already set.');
82
        }
83
        $this->params['Order']['OrderStatus'] = $orderStatus->getValue();
84
85
        return $this;
86
    }
87
88
    /**
89
     * 更新者名(ビジネスID登録氏名)
90
     *
91
     * @param string $operationUser
92
     * @return self
93
     */
94 View Code Duplication
    public function setOperationUser(string $operationUser): self
0 ignored issues
show
Duplication introduced by
This method 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...
95
    {
96
        if (isset($this->params['Target']['OperationUser'])) {
97
            throw new LogicException('OperationUser is already set.');
98
        }
99
100
        $this->params['Target']['OperationUser'] = $operationUser;
101
102
        return $this;
103
    }
104
105
    /**
106
     * キャンセル理由
107
     *
108
     * @param CancelReason $cancelReason
109
     * @return self
110
     */
111 View Code Duplication
    public function setCancelReason(CancelReason $cancelReason): self
0 ignored issues
show
Duplication introduced by
This method 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...
112
    {
113
        if (isset($this->params['Order']['CancelReason'])) {
114
            throw new LogicException('CancelReason is already set.');
115
        }
116
117
        $this->params['Order']['CancelReason'] = $cancelReason->getValue();
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getParams()
126
    {
127
        $this->validateRequest();
128
129
        $fluidXml = new FluidXml('Req');
130
        $fluidXml->add($this->params);
131
132
        return $fluidXml->xml();
133
    }
134
135
    /**
136
     * @throws InvalidRequestException
137
     */
138
    private function validateRequest(): void
139
    {
140
        if (!isset($this->params['SellerId'])) {
141
            throw new InvalidRequestException;
142
        }
143
        if (!isset($this->params['Target']['OrderId'])) {
144
            throw new InvalidRequestException;
145
        }
146
        if (!isset($this->params['Target']['IsPointFix'])) {
147
            throw new InvalidRequestException;
148
        }
149
        if (!isset($this->params['Order']['OrderStatus'])) {
150
            throw new InvalidRequestException;
151
        }
152
        // ※注文ステータスを「完了」に変更する際は、必ずポイント確定要否をtrueに指定してください。
153
        if ($this->params['Order']['OrderStatus'] === OrderStatus::PROCESSED()->getValue() && $this->params['Target']['IsPointFix'] === 'false') {
154
            throw new InvalidRequestException;
155
        }
156
    }
157
158
}
159