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

UpdateOrderShippingStatusRequest::setIsPointFix()   A

Complexity

Conditions 3
Paths 3

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