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

validateRequest()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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