Passed
Branch master (0e6cb9)
by C.
02:52 queued 49s
created

OrderService::changeOrder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 13

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of PHP CS Fixer.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *     Dariusz Rumiński <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Etrias\PaazlConnector\Services;
14
15
use DateTime;
16
use Etrias\PaazlConnector\Processor\Processor;
17
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType;
18
use Etrias\PaazlConnector\StructType\ChangeOrderRequest;
19
use Etrias\PaazlConnector\StructType\ChangeProducts;
20
use Etrias\PaazlConnector\StructType\ChangeSenderAddress;
21
use Etrias\PaazlConnector\StructType\ChangeShippingMethod;
22
use Etrias\PaazlConnector\StructType\CommitOrderRequest;
23
use Etrias\PaazlConnector\StructType\DeleteOrderRequest;
24
use Etrias\PaazlConnector\StructType\DeleteOrderResponse;
25
use Etrias\PaazlConnector\StructType\ListOrdersRequest;
26
use Etrias\PaazlConnector\StructType\ListOrdersResponse;
27
use Etrias\PaazlConnector\StructType\OrderDetailsRequest;
28
use Etrias\PaazlConnector\StructType\OrderDetailsResponse;
29
use Etrias\PaazlConnector\StructType\OrderRequest;
30
use Etrias\PaazlConnector\StructType\OrderSaveResponseType;
31
use Etrias\PaazlConnector\StructType\OrderStatusRequest;
32
use Etrias\PaazlConnector\StructType\OrderStatusResponse;
33
use Etrias\PaazlConnector\StructType\Products;
34
use Etrias\PaazlConnector\StructType\SenderAddress;
35
use Etrias\PaazlConnector\StructType\ShippingAddress;
36
use Etrias\PaazlConnector\StructType\ShippingMethod;
37
use Etrias\PaazlConnector\StructType\UpdateOrderRequest;
38
use Etrias\PaazlConnector\StructType\ValidateOrderRequest;
39
use Etrias\PaazlConnector\StructType\ValidateOrderResponseType;
40
41
class OrderService
42
{
43
    use Processor;
44
45
    /**
46
     * @var SecurityServiceInterface
47
     */
48
    protected $securityService;
49
    /**
50
     * @var GeneralServiceType
51
     */
52
    private $generalServiceType;
53
54
    /**
55
     * DocumentService constructor.
56
     *
57
     * @param GeneralServiceType       $generalServiceType
58
     * @param SecurityServiceInterface $securityService
59
     */
60
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
61
    {
62
        $this->securityService = $securityService;
63
        $this->generalServiceType = $generalServiceType;
64
    }
65
66
    /**
67
     * Constructor method for orderDetailsRequest.
68
     *
69
     * @param string $orderReference
70
     * @param int    $targetWebShop
71
     * @param bool   $extendedDetails
72
     *
73
     * @return OrderDetailsResponse
74
     */
75
    public function getOrderDetails($orderReference, $targetWebShop = null, $extendedDetails = null)
76
    {
77
        $request = new OrderDetailsRequest(
78
            $this->securityService->getHash($orderReference),
79
            $this->generalServiceType->getWebShopId(),
80
            $targetWebShop,
81
            $orderReference,
82
            $extendedDetails
83
        );
84
85
        $response = $this->generalServiceType->orderDetails($request);
86
87
        return $this->processResponse($response, $this->generalServiceType);
88
    }
89
90
    /**
91
     * @param $orderReference
92
     * @param Products $products
93
     * @param null     $targetWebShop
94
     *
95
     * @return OrderSaveResponseType
96
     */
97
    public function createOrder($orderReference, Products $products, $targetWebShop = null)
98
    {
99
        $request = new OrderRequest(
100
            $this->securityService->getHash($orderReference),
101
            $this->generalServiceType->getWebShopId(),
102
            $targetWebShop,
103
            $orderReference,
104
            $products
105
        );
106
107
        $response = $this->generalServiceType->order($request);
108
109
        return $this->processResponse($response, $this->generalServiceType);
110
    }
111
112
    /**
113
     * @param $orderReference
114
     * @param Products $products
115
     * @param null     $targetWebShop
116
     *
117
     * @return OrderSaveResponseType
118
     */
119
    public function updateOrder($orderReference, Products $products, $targetWebShop = null)
120
    {
121
        $request = new UpdateOrderRequest(
122
            $this->securityService->getHash($orderReference),
123
            $this->generalServiceType->getWebShopId(),
124
            $targetWebShop,
125
            $orderReference,
126
            $products
127
        );
128
129
        $response = $this->generalServiceType->updateorder($request);
130
131
        return $this->processResponse($response, $this->generalServiceType);
132
    }
133
134
    /**
135
     * @param $orderReference
136
     * @param null                      $newOrderReference
137
     * @param ChangeShippingMethod|null $shippingMethod
138
     * @param ShippingAddress|null      $shippingAddress
139
     * @param ChangeSenderAddress|null  $returnAddress
140
     * @param ChangeSenderAddress|null  $shipperAddress
141
     * @param ChangeProducts|null       $products
142
     * @param null                      $totalAmount
143
     * @param null                      $totalAmountCurrency
144
     * @param null                      $language
145
     * @param null                      $customerEmail
146
     * @param null                      $customerPhoneNumber
147
     * @param null                      $targetWebShop
148
     *
149
     * @return OrderSaveResponseType
150
     */
151
    public function changeOrder(
152
        $orderReference,
153
        $newOrderReference = null,
154
        ChangeShippingMethod $shippingMethod = null,
155
        ShippingAddress $shippingAddress = null,
156
        ChangeSenderAddress $returnAddress = null,
157
        ChangeSenderAddress $shipperAddress = null,
158
        ChangeProducts $products = null,
159
        $totalAmount = null,
160
        $totalAmountCurrency = null,
161
        $language = null,
162
        $customerEmail = null,
163
        $customerPhoneNumber = null,
164
        $targetWebShop = null
165
    ) {
166
        $request = new ChangeOrderRequest(
167
            $this->securityService->getHash($orderReference),
168
            $this->generalServiceType->getWebShopId(),
169
            $targetWebShop,
170
            $orderReference,
171
            $newOrderReference,
172
            $totalAmount,
173
            $totalAmountCurrency,
174
            $language,
175
            $customerEmail,
176
            $customerPhoneNumber,
177
            $shippingMethod,
178
            $shipperAddress,
179
            $returnAddress,
180
            $shippingAddress,
0 ignored issues
show
Bug introduced by
It seems like $shippingAddress can also be of type Etrias\PaazlConnector\StructType\ShippingAddress; however, parameter $shippingAddress of Etrias\PaazlConnector\St...rRequest::__construct() does only seem to accept Etrias\PaazlConnector\St...ngeShippingAddress|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

180
            /** @scrutinizer ignore-type */ $shippingAddress,
Loading history...
181
            $products
182
        );
183
184
        $response = $this->generalServiceType->changeOrder($request);
185
186
        return $this->processResponse($response, $this->generalServiceType);
187
    }
188
189
    /**
190
     * @param $orderReference
191
     * @param $pendingOrderReference
192
     * @param $totalAmount
193
     * @param $totalAmountCurrency
194
     * @param ShippingMethod     $shippingMethod
195
     * @param ShippingAddress    $shippingAddress
196
     * @param null               $customerEmail
197
     * @param null               $language
198
     * @param null               $customerPhoneNumber
199
     * @param SenderAddress|null $shipperAddress
200
     * @param SenderAddress|null $returnAddress
201
     * @param null               $targetWebShop
202
     *
203
     * @return ValidateOrderResponseType
204
     */
205
    public function validateOrder(
206
        $orderReference,
207
        $pendingOrderReference,
208
        $totalAmount,
209
        $totalAmountCurrency,
210
        ShippingMethod $shippingMethod,
211
        ShippingAddress $shippingAddress,
212
        $customerEmail = null,
213
        $language = null,
214
        $customerPhoneNumber = null,
215
        SenderAddress $shipperAddress = null,
216
        SenderAddress $returnAddress = null,
217
        $targetWebShop = null
218
    ) {
219
        $request = new ValidateOrderRequest(
220
            $this->securityService->getHash($pendingOrderReference),
221
            $this->generalServiceType->getWebShopId(),
222
            $targetWebShop,
223
            $orderReference,
224
            $pendingOrderReference,
225
            $totalAmount,
226
            $totalAmountCurrency,
227
            $language,
228
            $customerEmail,
229
            $customerPhoneNumber,
230
            $shippingMethod,
231
            $shipperAddress,
232
            $returnAddress,
233
            $shippingAddress
234
        );
235
236
        $response = $this->generalServiceType->validateOrder($request);
237
238
        return $this->processResponse($response, $this->generalServiceType);
239
    }
240
241
    /**
242
     * @param $orderReference
243
     * @param ShippingMethod     $shippingMethod
244
     * @param ShippingAddress    $shippingAddress
245
     * @param null               $totalAmount
246
     * @param null               $totalAmountCurrency
247
     * @param null               $language
248
     * @param null               $customerEmail
249
     * @param null               $customerPhoneNumber
250
     * @param SenderAddress|null $returnAddress
251
     * @param SenderAddress|null $shipperAddress
252
     * @param null               $pendingOrderReference
253
     * @param null               $targetWebShop
254
     *
255
     * @return OrderSaveResponseType
256
     */
257
    public function commitOrder(
258
        $orderReference,
259
        ShippingMethod $shippingMethod,
260
        ShippingAddress $shippingAddress,
261
        $totalAmount = null,
262
        $totalAmountCurrency = null,
263
        $language = null,
264
        $customerEmail = null,
265
        $customerPhoneNumber = null,
266
        SenderAddress $returnAddress = null,
267
        SenderAddress $shipperAddress = null,
268
        $pendingOrderReference = null,
269
        $targetWebShop = null
270
    ) {
271
        if ($pendingOrderReference === null) {
272
            $pendingOrderReference = $orderReference;
273
        }
274
275
        $request = new CommitOrderRequest(
276
            $this->securityService->getHash($pendingOrderReference),
277
            $this->generalServiceType->getWebShopId(),
278
            $targetWebShop,
279
            $orderReference,
280
            $pendingOrderReference,
281
            $totalAmount,
282
            $totalAmountCurrency,
283
            $language,
284
            $customerEmail,
285
            $customerPhoneNumber,
286
            $shippingMethod,
287
            $shipperAddress,
288
            $returnAddress,
289
            $shippingAddress
290
        );
291
292
        $response = $this->generalServiceType->commitOrder($request);
293
294
        return $this->processResponse($response, $this->generalServiceType);
295
    }
296
297
    /**
298
     * @param $orderReference
299
     * @param null $targetWebShop
300
     *
301
     * @return DeleteOrderResponse
302
     */
303
    public function deleteOrder($orderReference, $targetWebShop = null)
304
    {
305
        $request = new DeleteOrderRequest(
306
            $this->securityService->getHash($orderReference),
307
            $this->generalServiceType->getWebShopId(),
308
            $targetWebShop,
309
            $orderReference
310
        );
311
312
        $response = $this->generalServiceType->deleteOrder($request);
313
314
        return $this->processResponse($response, $this->generalServiceType);
315
    }
316
317
    /**
318
     * @param $orderReference
319
     * @param bool|null $includeLabels
320
     * @param bool|null $getCarrierStatus
321
     * @param null      $targetWebShop
322
     *
323
     * @return OrderStatusResponse
324
     */
325 View Code Duplication
    public function getOrderStatus(
326
        $orderReference,
327
        $includeLabels = null,
328
        $getCarrierStatus = null,
329
        $targetWebShop = null
330
    ) {
331
        $request = new OrderStatusRequest(
332
            $this->securityService->getHash($orderReference),
333
            $this->generalServiceType->getWebShopId(),
334
            $targetWebShop,
335
            $orderReference,
336
            $includeLabels,
337
            $getCarrierStatus
338
        );
339
340
        $response = $this->generalServiceType->orderStatus($request);
341
342
        return $this->processResponse($response, $this->generalServiceType);
343
    }
344
345
    /**
346
     * @param DateTime $changedSince
347
     * @param null     $page
348
     * @param null     $carrierStatus
349
     * @param null     $targetWebShop
350
     *
351
     * @return ListOrdersResponse
352
     */
353 View Code Duplication
    public function listOrders(DateTime $changedSince, $page = null, $carrierStatus = null, $targetWebShop = null)
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...
354
    {
355
        $today = new DateTime();
356
        $request = new ListOrdersRequest(
357
            $this->securityService->getHash($today->format('Ymd')),
358
            $this->generalServiceType->getWebShopId(),
359
            $targetWebShop,
360
            $changedSince->format('Y-m-d'),
361
            $page,
362
            $carrierStatus
363
        );
364
365
        $response = $this->generalServiceType->listOrders($request);
366
367
        return $this->processResponse($response, $this->generalServiceType);
368
    }
369
}
370