Test Failed
Push — develop ( cf0637...ea0f43 )
by Yuji
08:02
created

UpdateOrderShippingStatusRequest::setShipStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use DateTimeZone;
6
use InvalidArgumentException;
7
use LogicException;
8
use Shippinno\YahooShoppingJp\Api\UpdateOrderShippingStatusApi;
9
use Shippinno\YahooShoppingJp\Enum\ShipMethod;
10
use Shippinno\YahooShoppingJp\Enum\ShipStatus;
11
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException;
12
use Shippinno\YahooShoppingJp\Response\UpdateOrderShippingStatusResponse;
13
14
/**
15
 * Class UpdateOrderShippingStatusRequest
16
 * @package Shippinno\YahooShoppingJp\Request
17
 */
18
class UpdateOrderShippingStatusRequest extends AbstractRequest
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $params = [];
24
25
    /**
26
     * @param string $sellerId
27
     * @return self
28
     */
29 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...
30
    {
31
        if (isset($this->params['SellerId'])) {
32
            throw new LogicException('SellerId is already set.');
33
        }
34
35
        $this->params['SellerId'] = $sellerId;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param string $orderId
42
     * @return self
43
     */
44 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...
45
    {
46
        if (isset($this->params['Target']['OrderId'])) {
47
            throw new LogicException('OrderId is already set.');
48
        }
49
50
        $this->params['Target']['OrderId'] = $orderId;
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param bool $isPointFix
57
     * @return self
58
     */
59 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...
60
    {
61
        if (isset($this->params['Target']['IsPointFix'])) {
62
            throw new LogicException('IsPointFix is already set.');
63
        }
64
65
        $this->params['Target']['IsPointFix'] = $isPointFix ? 'true' : 'false';
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param string $operationUser
72
     * @return self
73
     */
74 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...
75
    {
76
        if (isset($this->params['Target']['OperationUser'])) {
77
            throw new LogicException('OperationUser is already set.');
78
        }
79
80
        $this->params['Target']['OperationUser'] = $operationUser;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @param ShipStatus $shipStatus
87
     * @return self
88
     */
89 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...
90
    {
91
        if (isset($this->params['Order']['Ship']['ShipStatus'])) {
92
            throw new LogicException('ShipStatus is already set.');
93
        }
94
95
        $this->params['Order']['Ship']['ShipStatus'] = $shipStatus->getValue();
96
97
        return $this;
98
    }
99
100
    /**
101
     * @param ShipMethod $shipMethod
102
     * @return self
103
     */
104 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...
105
    {
106
        if (isset($this->params['Order']['Ship']['ShipMethod'])) {
107
            throw new LogicException('ShipMethod is already set.');
108
        }
109
110
        $this->params['Order']['Ship']['ShipMethod'] = $shipMethod->getValue();
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
     * @throws InvalidRequestException
215
     */
216
    protected function validateParams(): void
217
    {
218
        if (!isset($this->params['SellerId'])) {
219
            throw new InvalidRequestException('SellerId is required.');
220
        }
221
222
        if (!isset($this->params['Target']['OrderId'])) {
223
            throw new InvalidRequestException('OrderId is required.');
224
        }
225
226
        if (!isset($this->params['Target']['IsPointFix'])) {
227
            throw new InvalidRequestException('IsPointFix is required.');
228
        }
229
230
        if (!isset($this->params['Order']['Ship']['ShipStatus'])) {
231
            throw new InvalidRequestException('ShipStatus is required.');
232
        }
233
    }
234
235
    /**
236
     * @return UpdateOrderShippingStatusApi
237
     */
238
    public function api()
239
    {
240
        return new UpdateOrderShippingStatusApi();
241
    }
242
243
    /**
244
     * @return UpdateOrderShippingStatusResponse
245
     */
246
    public function response()
247
    {
248
        return new UpdateOrderShippingStatusResponse();
249
    }
250
251
}
252