Test Failed
Push — develop ( fab808...f55317 )
by Yuji
03:48
created

SearchOrdersRequest::validateParams()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use DateTimeImmutable;
6
use FluidXml\FluidXml;
7
use InvalidArgumentException;
8
use LogicException;
9
use Shippinno\YahooShoppingJp\Api\AbstractApi;
10
use Shippinno\YahooShoppingJp\Api\SearchOrdersApi;
11
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException;
12
use Shippinno\YahooShoppingJp\Response\AbstractResponse;
13
use Shippinno\YahooShoppingJp\Response\SearchOrdersResponse;
14
15
class SearchOrdersRequest extends AbstractRequest
16
{
17
18
    public function __construct()
19
    {
20
        $this->params['Search']['Field'] = implode(',', [
21
            'OrderId',
22
            'Version',
23
            'OriginalOrderId',
24
            'ParentOrderId',
25
            'DeviceType',
26
            'IsSeen',
27
            'IsSplit',
28
            'IsRoyalty',
29
            'IsSeller',
30
            'IsAffiliate',
31
            'IsRatingB2s',
32
            'OrderTime',
33
            'ExistMultiReleaseDate',
34
            'ReleaseDate',
35
            'LastUpdateTime',
36
            'Suspect',
37
            'OrderStatus',
38
            'StoreStatus',
39
            'RoyaltyFixTime',
40
            'PrintSlipFlag',
41
            'PrintDeliveryFlag',
42
            'PrintBillFlag',
43
            'BuyerCommentsFlag',
44
            'PayStatus',
45
            'SettleStatus',
46
            'PayType',
47
            'PayMethod',
48
            'PayMethodName',
49
            'PayDate',
50
            'SettleId',
51
            'UseWallet',
52
            'NeedBillSlip',
53
            'NeedDetailedSlip',
54
            'NeedReceipt',
55
            'BillFirstName',
56
            'BillFirstNameKana',
57
            'BillLastName',
58
            'BillLastNameKana',
59
            'BillPrefecture',
60
            'ShipStatus',
61
            'ShipMethod',
62
            'ShipRequestDate',
63
            'ShipRequestTime',
64
            'ShipNotes',
65
            'ShipInvoiceNumber1',
66
            'ShipInvoiceNumber2',
67
            'ArriveType',
68
            'ShipDate',
69
            'NeedGiftWrap',
70
            'NeedGiftWrapMessage',
71
            'NeedGiftWrapPaper',
72
            'ShipFirstName',
73
            'ShipFirstNameKana',
74
            'ShipLastName',
75
            'ShipLastNameKana',
76
            'ShipPrefecture',
77
            'PayCharge',
78
            'ShipCharge',
79
            'GiftWrapCharge',
80
            'Discount',
81
            'UsePoint',
82
            'TotalPrice',
83
            'RefundTotalPrice',
84
            'UsePointType',
85
            'IsGetPointFixAll',
86
            'SellerId',
87
            'IsLogin',
88
            'PayNo',
89
            'PayNoIssueDate',
90
            'SellerType',
91
            'IsPayManagement',
92
            'ShipUrl',
93
            'ShipMethodName',
94
            'ArrivalDate',
95
            'TotalMallCouponDiscount',
96
        ]);
97
    }
98
99
    /**
100
     * @return AbstractApi
101
     */
102
    public function api()
103
    {
104
        return new SearchOrdersApi;
105
    }
106
107
    /**
108
     * @return AbstractResponse
109
     */
110
    public function response()
111
    {
112
        return new SearchOrdersResponse;
113
    }
114
115
    /**
116
     * @return void
117
     */
118
    protected function validateParams()
119
    {
120
        if (!isset($this->params['SellerId'])) {
121
            throw new InvalidRequestException;
122
        }
123
    }
124
125
126
    /**
127
     * @return string
128
     */
129
    public function getParams()
130
    {
131
        $this->validateParams();
132
133
        $fluidXml = new FluidXml('Req');
134
        $fluidXml->add($this->params);
135
136
        return $fluidXml->xml();
137
    }
138
139
    /**
140
     * @param string $sellerId
141
     * @return self
142
     */
143 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...
144
    {
145
        if (isset($this->params['SellerId'])) {
146
            throw new LogicException('SellerId is already set.');
147
        }
148
149
        $this->params['SellerId'] = $sellerId;
150
151
        return $this;
152
    }
153
154
    /**
155
     * @param null|DateTimeImmutable $from
156
     * @param null|DateTimeImmutable $to
157
     * @return self
158
     */
159
    public function setOrderedDateTimeRange(DateTimeImmutable $from = null, DateTimeImmutable $to = null): self
160
    {
161
        if (null === $from && null === $to) {
162
            throw new InvalidArgumentException('Either OrderTimeFrom or OrderTimeTo has to be set.');
163
        }
164
165
        if (null !== $from &&
166
            null !== $to &&
167
            $from > $to
168
        ) {
169
            throw new LogicException('OrderTimeFrom has to be earlier than OrderTimeTo.');
170
        }
171
172
        if (isset($this->params['Search']['Condition']['OrderTimeFrom'])) {
173
            throw new LogicException('OrderTimeFrom is already set.');
174
        }
175
176
        if (isset($this->params['Search']['Condition']['OrderTimeTo'])) {
177
            throw new LogicException('OrderTimeTo is already set.');
178
        }
179
180 View Code Duplication
        if (null !== $from) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
181
            $this->params['Search']['Condition']['OrderTimeFrom'] = $from->format('YmdHis');
182
        }
183
184 View Code Duplication
        if (null !== $to) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            $this->params['Search']['Condition']['OrderTimeTo'] = $to->format('YmdHis');
186
        }
187
188
        return $this;
189
    }
190
191
    /**
192
     * @param int $offset
193
     * @return self
194
     */
195 View Code Duplication
    public function setOffset(int $offset): 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...
196
    {
197
        if ($offset < 0) {
198
            throw new InvalidArgumentException;
199
        }
200
201
        if (isset($this->params['Search']['Start'])) {
202
            throw new LogicException('Start is already set.');
203
        }
204
205
        $this->params['Search']['Start'] = $offset + 1;
206
207
        return $this;
208
    }
209
210
    /**
211
     * @param int $limit
212
     * @return self
213
     */
214 View Code Duplication
    public function setLimit(int $limit): 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...
215
    {
216
        if ($limit < 0) {
217
            throw new InvalidArgumentException;
218
        }
219
220
        if (isset($this->params['Search']['Result'])) {
221
            throw new LogicException('Result is already set.');
222
        }
223
224
        $this->params['Search']['Result'] = $limit;
225
226
        return $this;
227
    }
228
229
}
230