Test Failed
Pull Request — master (#19)
by
unknown
02:23
created

UpdateOrderShippingStatusRequest   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 230
Duplicated Lines 55.65 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 32
lcom 1
cbo 4
dl 128
loc 230
rs 9.6
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
B validateRequest() 0 18 5
A setSellerId() 10 10 2
A setOrderId() 10 10 2
A setIsPointFix() 10 10 3
A setOperationUser() 10 10 2
A setShipStatus() 10 10 2
A setShipMethod() 10 10 2
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 9 1

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