Test Failed
Pull Request — master (#19)
by
unknown
03:33
created

UpdateOrderShippingStatusRequest   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 235
Duplicated Lines 45.96 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 35
lcom 1
cbo 3
dl 108
loc 235
rs 9
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setSellerId() 10 10 2
A setOrderId() 10 10 2
A setIsPointFix() 10 10 3
A setOperationUser() 10 10 2
A setShipStatus() 0 10 2
A setShipMethod() 0 16 4
A setShipNotes() 14 14 3
A setShipInvoiceNumber1() 10 10 2
A setShipInvoiceNumber2() 10 10 2
A setShipUrl() 10 10 2
A setShipDate() 12 12 2
A setArrivalDate() 12 12 2
A getParams() 0 6 1
B validateRequest() 0 18 5

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 DateTimeZone;
6
use InvalidArgumentException;
7
use LogicException;
8
use Shippinno\YahooShoppingJp\Enum\ShipStatus;
9
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException;
10
11
class UpdateOrderShippingStatusRequest extends AbstractRequest
12
{
13
    private $params = [];
14
15
    public function __construct()
16
    {
17
    }
18
19
    /**
20
     * @param string $sellerId
21
     * @return self
22
     */
23 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...
24
    {
25
        if (isset($this->params['SellerId'])) {
26
            throw new LogicException('SellerId is already set.');
27
        }
28
29
        $this->params['SellerId'] = $sellerId;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @param string $orderId
36
     * @return self
37
     */
38 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...
39
    {
40
        if (isset($this->params['Target']['OrderId'])) {
41
            throw new LogicException('OrderId is already set.');
42
        }
43
44
        $this->params['Target']['OrderId'] = $orderId;
45
46
        return $this;
47
    }
48
49
    /**
50
     * @param bool $isPointFix
51
     * @return self
52
     */
53 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...
54
    {
55
        if (isset($this->params['Target']['IsPointFix'])) {
56
            throw new LogicException('IsPointFix is already set.');
57
        }
58
59
        $this->params['Target']['IsPointFix'] = $isPointFix ? 'true' : 'false';
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param string $operationUser
66
     * @return self
67
     */
68 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...
69
    {
70
        if (isset($this->params['Target']['OperationUser'])) {
71
            throw new LogicException('OperationUser is already set.');
72
        }
73
74
        $this->params['Target']['OperationUser'] = $operationUser;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param ShipStatus $shipStatus
81
     * @return self
82
     */
83
    public function setShipStatus(ShipStatus $shipStatus): self
84
    {
85
        if (isset($this->params['Order']['Ship']['ShipStatus'])) {
86
            throw new LogicException('ShipStatus is already set.');
87
        }
88
89
        $this->params['Order']['Ship']['ShipStatus'] = $shipStatus->getValue();
90
91
        return $this;
92
    }
93
94
    /**
95
     * @param string $shipMethod
96
     * @return self
97
     */
98
    public function setShipMethod(string $shipMethod): self
99
    {
100
        if (isset($this->params['Order']['Ship']['ShipMethod'])) {
101
            throw new LogicException('ShipMethod is already set.');
102
        }
103
104
        if(!preg_match('/^postage(\d+)$/',$shipMethod,$m)
105
            || !in_array($m[1],['1','2','3','4','5','6','7','8',
106
                '9','10','11','12','13','14','16'])){
107
            throw new InvalidArgumentException('ShipMethod is invalid.');
108
        }
109
110
        $this->params['Order']['Ship']['ShipMethod'] = $shipMethod;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @param string $shipNotes
117
     * @return self
118
     */
119 View Code Duplication
    public function setShipNotes(string $shipNotes): 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...
120
    {
121
        if (isset($this->params['Order']['Ship']['ShipNotes'])) {
122
            throw new LogicException('ShipNotes is already set.');
123
        }
124
125
        if(strlen($shipNotes) > 500){
126
            throw new InvalidArgumentException('ShipNotes is invalid.');
127
        }
128
129
        $this->params['Order']['Ship']['ShipNotes'] = $shipNotes;
130
131
        return $this;
132
    }
133
134
    /**
135
     * @param string $shipInvoiceNumber1
136
     * @return self
137
     */
138 View Code Duplication
    public function setShipInvoiceNumber1(string $shipInvoiceNumber1): 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...
139
    {
140
        if (isset($this->params['Order']['Ship']['ShipInvoiceNumber1'])) {
141
            throw new LogicException('ShipInvoiceNumber1 is already set.');
142
        }
143
144
        $this->params['Order']['Ship']['ShipInvoiceNumber1'] = $shipInvoiceNumber1;
145
146
        return $this;
147
    }
148
149
    /**
150
     * @param string $shipInvoiceNumber2
151
     * @return self
152
     */
153 View Code Duplication
    public function setShipInvoiceNumber2(string $shipInvoiceNumber2): 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...
154
    {
155
        if (isset($this->params['Order']['Ship']['ShipInvoiceNumber2'])) {
156
            throw new LogicException('ShipInvoiceNumber2 is already set.');
157
        }
158
159
        $this->params['Order']['Ship']['ShipInvoiceNumber2'] = $shipInvoiceNumber2;
160
161
        return $this;
162
    }
163
164
    /**
165
     * @param string $shipUrl
166
     * @return self
167
     */
168 View Code Duplication
    public function setShipUrl(string $shipUrl): 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...
169
    {
170
        if (isset($this->params['Order']['Ship']['ShipUrl'])) {
171
            throw new LogicException('ShipUrl is already set.');
172
        }
173
174
        $this->params['Order']['Ship']['ShipUrl'] = '![CDATA['.$shipUrl.']]';
175
176
        return $this;
177
    }
178
179
    /**
180
     * @param \DateTimeImmutable $shipDate
181
     * @return self
182
     */
183 View Code Duplication
    public function setShipDate(\DateTimeImmutable $shipDate): 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...
184
    {
185
        if (isset($this->params['Order']['Ship']['ShipDate'])) {
186
            throw new LogicException('ShipDate is already set.');
187
        }
188
189
        $this->params['Order']['Ship']['ShipDate'] = $shipDate
190
                                                ->setTimeZone(new DateTimeZone('Asia/Tokyo'))
191
                                                ->format('Ymd');
192
193
        return $this;
194
    }
195
196
    /**
197
     * @param \DateTimeImmutable $arrivalDate
198
     * @return self
199
     */
200 View Code Duplication
    public function setArrivalDate(\DateTimeImmutable $arrivalDate): 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...
201
    {
202
        if (isset($this->params['Order']['Ship']['ArrivalDate'])) {
203
            throw new LogicException('ArrivalDate is already set.');
204
        }
205
206
        $this->params['Order']['Ship']['ArrivalDate'] = $arrivalDate
207
                                                    ->setTimeZone(new DateTimeZone('Asia/Tokyo'))
208
                                                    ->format('Ymd');
209
210
        return $this;
211
    }
212
213
    /**
214
     * getParams
215
     * @return array
216
     */
217
    public function getParams(): array
218
    {
219
        $this->validateRequest();
220
221
        return $this->params;
222
    }
223
224
    /**
225
     * @throws InvalidRequestException
226
     */
227
    private function validateRequest(): void
228
    {
229
        if (!isset($this->params['SellerId'])) {
230
            throw new InvalidRequestException('SellerId is required.');
231
        }
232
233
        if (!isset($this->params['Target']['OrderId'])) {
234
            throw new InvalidRequestException('OrderId is required.');
235
        }
236
237
        if (!isset($this->params['Target']['IsPointFix'])) {
238
            throw new InvalidRequestException('IsPointFix is required.');
239
        }
240
241
        if (!isset($this->params['Order']['Ship']['ShipStatus'])) {
242
            throw new InvalidRequestException('ShipStatus is required.');
243
        }
244
    }
245
}
246