Passed
Push — master ( 14d404...4bd91f )
by C.
02:09
created

OrderService::createOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
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\Service;
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 OrderServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\OrderServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
     */
52
    protected $orderServiceType;
53
    /**
54
     * @var UpdateServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\UpdateServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
     */
56
    protected $updateServiceType;
57
    /**
58
     * @var ChangeServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\ChangeServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
     */
60
    protected $changeServiceType;
61
    /**
62
     * @var DeleteServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\DeleteServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
     */
64
    protected $deleteServiceType;
65
    /**
66
     * @var CommitServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\CommitServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     */
68
    protected $commitServiceType;
69
    /**
70
     * @var ListServiceType
0 ignored issues
show
Bug introduced by
The type Etrias\PaazlConnector\Service\ListServiceType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
71
     */
72
    protected $listServiceType;
73
    /**
74
     * @var GeneralServiceType
75
     */
76
    private $generalServiceType;
77
78
    /**
79
     * DocumentService constructor.
80
     *
81
     * @param GeneralServiceType       $generalServiceType
82
     * @param SecurityServiceInterface $securityService
83
     */
84
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
85
    {
86
        $this->securityService = $securityService;
87
        $this->generalServiceType = $generalServiceType;
88
    }
89
90
    /**
91
     * Constructor method for orderDetailsRequest.
92
     *
93
     * @param string $orderReference
94
     * @param int    $targetWebShop
95
     * @param bool   $extendedDetails
96
     *
97
     * @return OrderDetailsResponse
98
     */
99
    public function getOrderDetails($orderReference, $targetWebShop = null, $extendedDetails = null)
100
    {
101
        $request = new OrderDetailsRequest(
102
            $this->securityService->getHash($orderReference),
103
            $this->generalServiceType->getWebShopId(),
104
            $targetWebShop,
105
            $orderReference,
106
            $extendedDetails
107
        );
108
109
        $response = $this->generalServiceType->orderDetails($request);
110
111
        return $this->processResponse($response, $this->generalServiceType);
112
    }
113
114
    /**
115
     * @param $orderReference
116
     * @param Products $products
117
     * @param null     $targetWebShop
118
     *
119
     * @return OrderSaveResponseType
120
     */
121
    public function createOrder($orderReference, Products $products, $targetWebShop = null)
122
    {
123
        $request = new OrderRequest(
124
            $this->securityService->getHash($orderReference),
125
            $this->generalServiceType->getWebShopId(),
126
            $targetWebShop,
127
            $orderReference,
128
            $products
129
        );
130
131
        $response = $this->generalServiceType->order($request);
132
133
        return $this->processResponse($response, $this->generalServiceType);
134
    }
135
136
    /**
137
     * @param $orderReference
138
     * @param Products $products
139
     * @param null     $targetWebShop
140
     *
141
     * @return OrderSaveResponseType
142
     */
143
    public function updateOrder($orderReference, Products $products, $targetWebShop = null)
144
    {
145
        $request = new UpdateOrderRequest(
146
            $this->securityService->getHash($orderReference),
147
            $this->generalServiceType->getWebShopId(),
148
            $targetWebShop,
149
            $orderReference,
150
            $products
151
        );
152
153
        $response = $this->generalServiceType->updateorder($request);
154
155
        return $this->processResponse($response, $this->generalServiceType);
156
    }
157
158
    /**
159
     * @param $orderReference
160
     * @param null                      $newOrderReference
161
     * @param ChangeShippingMethod|null $shippingMethod
162
     * @param ShippingAddress|null      $shippingAddress
163
     * @param ChangeSenderAddress|null  $returnAddress
164
     * @param ChangeSenderAddress|null  $shipperAddress
165
     * @param ChangeProducts|null       $products
166
     * @param null                      $totalAmount
167
     * @param null                      $totalAmountCurrency
168
     * @param null                      $language
169
     * @param null                      $customerEmail
170
     * @param null                      $customerPhoneNumber
171
     * @param null                      $targetWebShop
172
     *
173
     * @return OrderSaveResponseType
174
     */
175
    public function changeOrder(
176
        $orderReference,
177
        $newOrderReference = null,
178
        ChangeShippingMethod $shippingMethod = null,
179
        ShippingAddress $shippingAddress = null,
180
        ChangeSenderAddress $returnAddress = null,
181
        ChangeSenderAddress $shipperAddress = null,
182
        ChangeProducts $products = null,
183
        $totalAmount = null,
184
        $totalAmountCurrency = null,
185
        $language = null,
186
        $customerEmail = null,
187
        $customerPhoneNumber = null,
188
        $targetWebShop = null
189
    ) {
190
        $request = new ChangeOrderRequest(
191
            $this->securityService->getHash($orderReference),
192
            $this->generalServiceType->getWebShopId(),
193
            $targetWebShop,
194
            $orderReference,
195
            $newOrderReference,
196
            $totalAmount,
197
            $totalAmountCurrency,
198
            $language,
199
            $customerEmail,
200
            $customerPhoneNumber,
201
            $shippingMethod,
202
            $shipperAddress,
203
            $returnAddress,
204
            $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

204
            /** @scrutinizer ignore-type */ $shippingAddress,
Loading history...
205
            $products
206
        );
207
208
        $response = $this->generalServiceType->changeOrder($request);
209
210
        return $this->processResponse($response, $this->generalServiceType);
211
    }
212
213
    /**
214
     * @param $orderReference
215
     * @param $pendingOrderReference
216
     * @param $totalAmount
217
     * @param $totalAmountCurrency
218
     * @param ShippingMethod     $shippingMethod
219
     * @param ShippingAddress    $shippingAddress
220
     * @param null               $customerEmail
221
     * @param null               $language
222
     * @param null               $customerPhoneNumber
223
     * @param SenderAddress|null $shipperAddress
224
     * @param SenderAddress|null $returnAddress
225
     * @param null               $targetWebShop
226
     *
227
     * @return ValidateOrderResponseType
228
     */
229
    public function validateOrder(
230
        $orderReference,
231
        $pendingOrderReference,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $pendingOrderReference exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
232
        $totalAmount,
233
        $totalAmountCurrency,
234
        ShippingMethod $shippingMethod,
235
        ShippingAddress $shippingAddress,
236
        $customerEmail = null,
237
        $language = null,
238
        $customerPhoneNumber = null,
239
        SenderAddress $shipperAddress = null,
240
        SenderAddress $returnAddress = null,
241
        $targetWebShop = null
242
    ) {
243
        $request = new ValidateOrderRequest(
244
            $this->securityService->getHash($pendingOrderReference),
245
            $this->generalServiceType->getWebShopId(),
246
            $targetWebShop,
247
            $orderReference,
248
            $pendingOrderReference,
249
            $totalAmount,
250
            $totalAmountCurrency,
251
            $language,
252
            $customerEmail,
253
            $customerPhoneNumber,
254
            $shippingMethod,
255
            $shipperAddress,
256
            $returnAddress,
257
            $shippingAddress
258
        );
259
260
        $response = $this->generalServiceType->validateOrder($request);
261
262
        return $this->processResponse($response, $this->generalServiceType);
263
    }
264
265
    /**
266
     * @param $orderReference
267
     * @param ShippingMethod     $shippingMethod
268
     * @param ShippingAddress    $shippingAddress
269
     * @param null               $totalAmount
270
     * @param null               $totalAmountCurrency
271
     * @param null               $language
272
     * @param null               $customerEmail
273
     * @param null               $customerPhoneNumber
274
     * @param SenderAddress|null $returnAddress
275
     * @param SenderAddress|null $shipperAddress
276
     * @param null               $pendingOrderReference
277
     * @param null               $targetWebShop
278
     *
279
     * @return OrderSaveResponseType
280
     */
281
    public function commitOrder(
282
        $orderReference,
283
        ShippingMethod $shippingMethod,
284
        ShippingAddress $shippingAddress,
285
        $totalAmount = null,
286
        $totalAmountCurrency = null,
287
        $language = null,
288
        $customerEmail = null,
289
        $customerPhoneNumber = null,
290
        SenderAddress $returnAddress = null,
291
        SenderAddress $shipperAddress = null,
292
        $pendingOrderReference = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $pendingOrderReference exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
293
        $targetWebShop = null
294
    ) {
295
        if ($pendingOrderReference === null) {
296
            $pendingOrderReference = $orderReference;
297
        }
298
299
        $request = new CommitOrderRequest(
300
            $this->securityService->getHash($pendingOrderReference),
301
            $this->generalServiceType->getWebShopId(),
302
            $targetWebShop,
303
            $orderReference,
304
            $pendingOrderReference,
305
            $totalAmount,
306
            $totalAmountCurrency,
307
            $language,
308
            $customerEmail,
309
            $customerPhoneNumber,
310
            $shippingMethod,
311
            $shipperAddress,
312
            $returnAddress,
313
            $shippingAddress
314
        );
315
316
        $response = $this->generalServiceType->commitOrder($request);
317
318
        return $this->processResponse($response, $this->generalServiceType);
319
    }
320
321
    /**
322
     * @param $orderReference
323
     * @param null $targetWebShop
324
     *
325
     * @return DeleteOrderResponse
326
     */
327
    public function deleteOrder($orderReference, $targetWebShop = null)
328
    {
329
        $request = new DeleteOrderRequest(
330
            $this->securityService->getHash($orderReference),
331
            $this->generalServiceType->getWebShopId(),
332
            $targetWebShop,
333
            $orderReference
334
        );
335
336
        $response = $this->generalServiceType->deleteOrder($request);
337
338
        return $this->processResponse($response, $this->generalServiceType);
339
    }
340
341
    /**
342
     * @param $orderReference
343
     * @param bool|null $includeLabels
344
     * @param bool|null $getCarrierStatus
345
     * @param null      $targetWebShop
346
     *
347
     * @return OrderStatusResponse
348
     */
349 View Code Duplication
    public function getOrderStatus(
350
        $orderReference,
351
        $includeLabels = null,
352
        $getCarrierStatus = null,
353
        $targetWebShop = null
354
    ) {
355
        $request = new OrderStatusRequest(
356
            $this->securityService->getHash($orderReference),
357
            $this->generalServiceType->getWebShopId(),
358
            $targetWebShop,
359
            $orderReference,
360
            $includeLabels,
361
            $getCarrierStatus
362
        );
363
364
        $response = $this->generalServiceType->orderStatus($request);
365
366
        return $this->processResponse($response, $this->generalServiceType);
367
    }
368
369
    /**
370
     * @param DateTime $changedSince
371
     * @param null     $page
372
     * @param null     $carrierStatus
373
     * @param null     $targetWebShop
374
     *
375
     * @return ListOrdersResponse
376
     */
377 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...
378
    {
379
        $today = new DateTime();
380
        $request = new ListOrdersRequest(
381
            $this->securityService->getHash($today->format('Ymd')),
382
            $this->generalServiceType->getWebShopId(),
383
            $targetWebShop,
384
            $changedSince->format('Y-m-d'),
385
            $page,
386
            $carrierStatus
387
        );
388
389
        $response = $this->generalServiceType->listOrders($request);
390
391
        return $this->processResponse($response, $this->generalServiceType);
392
    }
393
}
394