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

LabelService::getExistingPdfLabels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 13
nc 2
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\Services;
14
15
use Etrias\PaazlConnector\Processor\Processor;
16
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType;
17
use Etrias\PaazlConnector\StructType\ExistingLabelType;
18
use Etrias\PaazlConnector\StructType\GenerateExtraImageLabelRequest;
19
use Etrias\PaazlConnector\StructType\GenerateExtraImageLabelResponse;
20
use Etrias\PaazlConnector\StructType\GenerateExtraImageReturnLabelResponse;
21
use Etrias\PaazlConnector\StructType\GenerateExtraPdfLabelRequest;
22
use Etrias\PaazlConnector\StructType\GenerateExtraPdfLabelResponse;
23
use Etrias\PaazlConnector\StructType\GenerateExtraPdfReturnLabelRequest;
24
use Etrias\PaazlConnector\StructType\GenerateExtraPdfReturnLabelResponse;
25
use Etrias\PaazlConnector\StructType\GenerateImageLabelsRequest;
26
use Etrias\PaazlConnector\StructType\GenerateImageLabelsResponse;
27
use Etrias\PaazlConnector\StructType\GenerateImageReturnLabelsResponse;
28
use Etrias\PaazlConnector\StructType\GeneratePdfLabelsRequest;
29
use Etrias\PaazlConnector\StructType\GeneratePdfLabelsResponse;
30
use Etrias\PaazlConnector\StructType\GeneratePdfReturnLabelsRequest;
31
use Etrias\PaazlConnector\StructType\GeneratePdfReturnLabelsResponse;
32
use Etrias\PaazlConnector\StructType\GenerateZplLabelsRequest;
33
use Etrias\PaazlConnector\StructType\GenerateZplLabelsResponse;
34
use Etrias\PaazlConnector\StructType\GetExistingImageLabelResponse;
35
use Etrias\PaazlConnector\StructType\GetExistingImageLabelsResponse;
36
use Etrias\PaazlConnector\StructType\GetExistingPdfLabelRequest;
37
use Etrias\PaazlConnector\StructType\GetExistingPdfLabelResponse;
38
use Etrias\PaazlConnector\StructType\GetExistingPdfLabelsRequest;
39
use Etrias\PaazlConnector\StructType\GetExistingPdfLabelsResponse;
40
use Etrias\PaazlConnector\StructType\OrderType;
41
use Etrias\PaazlConnector\StructType\ReturnLabelsOrderType;
42
43
class LabelService
44
{
45
    use Processor;
46
47
    /**
48
     * @var SecurityServiceInterface
49
     */
50
    protected $securityService;
51
    /**
52
     * @var GeneralServiceType
53
     */
54
    private $generalServiceType;
55
56
    /**
57
     * DocumentService constructor.
58
     *
59
     * @param GeneralServiceType       $generalServiceType
60
     * @param SecurityServiceInterface $securityService
61
     */
62
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
63
    {
64
        $this->securityService = $securityService;
65
        $this->generalServiceType = $generalServiceType;
66
    }
67
68
    /**
69
     * @param array $orderReferences
70
     * @param null  $printer
71
     * @param null  $includeMetaData
72
     * @param null  $batch
73
     * @param null  $targetWebShop
74
     *
75
     * @return GeneratePdfLabelsResponse
76
     */
77 View Code Duplication
    public function generatePdfLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null)
1 ignored issue
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...
78
    {
79
        $orders = [];
80
81
        foreach ($orderReferences as $orderReference) {
82
            $orders[] = new OrderType(
83
                $this->securityService->getHash($orderReference),
84
                $targetWebShop,
85
                $orderReference,
86
                null,
87
                $batch
88
            );
89
        }
90
91
        $request = new GeneratePdfLabelsRequest(
92
            $this->generalServiceType->getWebShopId(),
93
            $printer,
94
            $orders,
95
            $includeMetaData
96
        );
97
98
        $response = $this->generalServiceType->generatePdfLabels($request);
99
100
        return $this->processResponse($response, $this->generalServiceType);
101
    }
102
103
    /**
104
     * @param $orderReference
105
     * @param null $printer
106
     * @param null $includeMetaData
107
     * @param null $batch
108
     * @param null $targetWebShop
109
     *
110
     * @return GenerateExtraPdfLabelResponse
111
     */
112
    public function generateExtraPdfLabel($orderReference, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null)
113
    {
114
        $request = new GenerateExtraPdfLabelRequest(
115
            $this->securityService->getHash($orderReference),
116
            $this->generalServiceType->getWebShopId(),
117
            $targetWebShop,
118
            $orderReference,
119
            $printer,
120
            $batch,
121
            $includeMetaData
122
        );
123
124
        $response = $this->generalServiceType->generateExtraPdfLabel($request);
125
126
        return $this->processResponse($response, $this->generalServiceType);
127
    }
128
129
    /**
130
     * @param array $orderReferences
131
     * @param $shippingOption
132
     * @param null $printer
133
     * @param null $targetWebShop
134
     *
135
     * @return GeneratePdfReturnLabelsResponse
136
     */
137
    public function generatePdfReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null)
138
    {
139
        $orders = [];
140
141
        foreach ($orderReferences as $orderReference) {
142
            $orders[] = new ReturnLabelsOrderType(
143
                $this->securityService->getHash($orderReference),
144
                $targetWebShop,
145
                $orderReference,
146
                null,
147
                $shippingOption
148
            );
149
        }
150
151
        $request = new GeneratePdfReturnLabelsRequest(
152
            $printer
153
        );
154
        $request->setWebshop($this->generalServiceType->getWebShopId());
155
        $request->setOrder($orders);
156
157
        $response = $this->generalServiceType->generatePdfReturnLabels($request);
158
159
        return $this->processResponse($response, $this->generalServiceType);
160
    }
161
162
    /**
163
     * @param $orderReference
164
     * @param $shippingOption
165
     * @param null $printer
166
     * @param null $targetWebShop
167
     *
168
     * @return GenerateExtraPdfReturnLabelResponse
169
     */
170 View Code Duplication
    public function generateExtraPdfReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null)
171
    {
172
        $request = new GenerateExtraPdfReturnLabelRequest($printer);
173
        $request->setShippingOption($shippingOption)
174
            ->setWebshop($this->generalServiceType->getWebShopId())
175
            ->setHash($this->securityService->getHash($orderReference))
176
            ->setTargetWebshop($targetWebShop)
177
            ->setOrderReference($orderReference)
178
            ->setShippingOption($shippingOption);
179
180
        $response = $this->generalServiceType->generateExtraPdfReturnLabel($request);
181
182
        return $this->processResponse($response, $this->generalServiceType);
183
    }
184
185
    /**
186
     * @param array $orderReferences
187
     * @param null  $includeMetaData
188
     * @param null  $batch
189
     * @param null  $targetWebShop
190
     *
191
     * @return GenerateImageLabelsResponse
192
     */
193 View Code Duplication
    public function generateImageLabels(array $orderReferences, $includeMetaData = null, $batch = null, $targetWebShop = null)
1 ignored issue
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...
194
    {
195
        $orders = [];
196
197
        foreach ($orderReferences as $orderReference) {
198
            $orders[] = new OrderType(
199
                $this->securityService->getHash($orderReference),
200
                $targetWebShop,
201
                $orderReference,
202
                null,
203
                $batch
204
            );
205
        }
206
207
        $request = new GenerateImageLabelsRequest(
208
            $this->generalServiceType->getWebShopId(),
209
            $orders,
210
            $includeMetaData
211
        );
212
213
        $response = $this->generalServiceType->generateImageLabels($request);
214
215
        return $this->processResponse($response, $this->generalServiceType);
216
    }
217
218
    /**
219
     * @param array $orderReferences
220
     * @param $shippingOption
221
     * @param null $printer
222
     * @param null $targetWebShop
223
     *
224
     * @return GenerateImageReturnLabelsResponse
225
     */
226
    public function generateImageReturnLabels(array $orderReferences, $shippingOption, $printer = null, $targetWebShop = null)
227
    {
228
        $orders = [];
229
230
        foreach ($orderReferences as $orderReference) {
231
            $orders[] = new ReturnLabelsOrderType(
232
                $this->securityService->getHash($orderReference),
233
                $targetWebShop,
234
                $orderReference,
235
                null,
236
                $shippingOption
237
            );
238
        }
239
240
        $request = new GeneratePdfReturnLabelsRequest(
241
            $printer
242
        );
243
        $request->setWebshop($this->generalServiceType->getWebShopId());
244
        $request->setOrder($orders);
245
246
        $response = $this->generalServiceType->generateImageReturnLabels($request);
247
248
        return $this->processResponse($response, $this->generalServiceType);
249
    }
250
251
    /**
252
     * @param $orderReference
253
     * @param $shippingOption
254
     * @param null $printer
255
     * @param null $targetWebShop
256
     *
257
     * @return GenerateExtraImageReturnLabelResponse
258
     */
259 View Code Duplication
    public function generateExtraImageReturnLabel($orderReference, $shippingOption, $printer = null, $targetWebShop = null)
260
    {
261
        $request = new GenerateExtraPdfReturnLabelRequest($printer);
262
        $request->setShippingOption($shippingOption)
263
            ->setWebshop($this->generalServiceType->getWebShopId())
264
            ->setHash($this->securityService->getHash($orderReference))
265
            ->setTargetWebshop($targetWebShop)
266
            ->setOrderReference($orderReference)
267
            ->setShippingOption($shippingOption);
268
269
        $response = $this->generalServiceType->generateExtraImageReturnLabel($request);
270
271
        return $this->processResponse($response, $this->generalServiceType);
272
    }
273
274
    /**
275
     * @param $orderReference
276
     * @param null $includeMetaData
277
     * @param null $batch
278
     * @param null $targetWebShop
279
     *
280
     * @return GenerateExtraImageLabelResponse
281
     */
282
    public function generateExtraImageLabel($orderReference, $includeMetaData = null, $batch = null, $targetWebShop = null)
283
    {
284
        $request = new GenerateExtraImageLabelRequest(
285
            $this->securityService->getHash($orderReference),
286
            $this->generalServiceType->getWebShopId(),
287
            $targetWebShop,
288
            $orderReference,
289
            $batch,
290
            $includeMetaData
291
        );
292
293
        $response = $this->generalServiceType->generateExtraImageLabel($request);
294
295
        return $this->processResponse($response, $this->generalServiceType);
296
    }
297
298
    /**
299
     * @param array $orderReferences
300
     * @param null  $printer
301
     * @param null  $includeMetaData
302
     * @param null  $batch
303
     * @param null  $targetWebShop
304
     *
305
     * @return GenerateZplLabelsResponse
306
     */
307 View Code Duplication
    public function generateZplLabels(array $orderReferences, $printer = null, $includeMetaData = null, $batch = null, $targetWebShop = null)
1 ignored issue
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...
308
    {
309
        $orders = [];
310
311
        foreach ($orderReferences as $orderReference) {
312
            $orders[] = new OrderType(
313
                $this->securityService->getHash($orderReference),
314
                $targetWebShop,
315
                $orderReference,
316
                null,
317
                $batch
318
            );
319
        }
320
321
        $request = new GenerateZplLabelsRequest(
322
            $this->generalServiceType->getWebShopId(),
323
            $printer,
324
            $orders,
325
            $includeMetaData
326
        );
327
328
        $response = $this->generalServiceType->generateZplLabels($request);
329
330
        return $this->processResponse($response, $this->generalServiceType);
331
    }
332
333
    /**
334
     * @param $orderReference
335
     * @param $barCode
336
     * @param null $printer
337
     * @param null $includeMetaData
338
     * @param null $targetWebShop
339
     *
340
     * @return GetExistingPdfLabelResponse
341
     */
342 View Code Duplication
    public function getExistingPdfLabel($orderReference, $barCode, $printer = null, $includeMetaData = null, $targetWebShop = null)
343
    {
344
        $request = new GetExistingPdfLabelRequest($printer);
345
        $request->setHash($this->securityService->getHash($orderReference))
346
            ->setWebshop($this->generalServiceType->getWebShopId())
347
            ->setOrderReference($orderReference)
348
            ->setBarcode($barCode)
349
            ->setIncludeMetaData($includeMetaData)
350
            ->setTargetWebshop($targetWebShop);
351
352
        $response = $this->generalServiceType->getExistingPdfLabel($request);
353
354
        return $this->processResponse($response, $this->generalServiceType);
355
    }
356
357
    /**
358
     * @param array $barCodes        [$orderReference => $barcode]
359
     * @param null  $printer
360
     * @param null  $includeMetaData
361
     *
362
     * @return GetExistingPdfLabelsResponse
363
     */
364 View Code Duplication
    public function getExistingPdfLabels(array $barCodes, $printer = null, $includeMetaData = 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...
365
    {
366
        $labels = [];
367
368
        foreach ($barCodes as $orderReference => $barcode) {
369
            $labels[] = new ExistingLabelType(
370
                $this->securityService->getHash($orderReference),
371
                $this->generalServiceType->getWebShopId(),
372
                $orderReference,
373
                $barcode
374
            );
375
        }
376
377
        $request = new GetExistingPdfLabelsRequest($printer);
378
        $request->setLabel($labels)
379
            ->setWebshop($this->generalServiceType->getWebShopId())
380
            ->setIncludeMetaData($includeMetaData);
381
382
        $response = $this->generalServiceType->getExistingPdfLabels($request);
383
384
        return $this->processResponse($response, $this->generalServiceType);
385
    }
386
387
    /**
388
     * @param $orderReference
389
     * @param $barCode
390
     * @param null $includeMetaData
391
     * @param null $targetWebShop
392
     *
393
     * @return GetExistingImageLabelResponse
394
     */
395 View Code Duplication
    public function getExistingImageLabel($orderReference, $barCode, $includeMetaData = null, $targetWebShop = null)
396
    {
397
        $request = new GetExistingPdfLabelRequest();
398
        $request->setHash($this->securityService->getHash($orderReference))
399
            ->setWebshop($this->generalServiceType->getWebShopId())
400
            ->setOrderReference($orderReference)
401
            ->setBarcode($barCode)
402
            ->setIncludeMetaData($includeMetaData)
403
            ->setTargetWebshop($targetWebShop);
404
405
        $response = $this->generalServiceType->getExistingImageLabel($request);
406
407
        return $this->processResponse($response, $this->generalServiceType);
408
    }
409
410
    /**
411
     * @param array $barCodes        [$orderReference => $barcode]
412
     * @param null  $includeMetaData
413
     *
414
     * @return GetExistingImageLabelsResponse
415
     */
416 View Code Duplication
    public function getExistingImageLabels(array $barCodes, $includeMetaData = 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...
417
    {
418
        $labels = [];
419
420
        foreach ($barCodes as $orderReference => $barcode) {
421
            $labels[] = new ExistingLabelType(
422
                $this->securityService->getHash($orderReference),
423
                $this->generalServiceType->getWebShopId(),
424
                $orderReference,
425
                $barcode
426
            );
427
        }
428
429
        $request = new GetExistingPdfLabelsRequest();
430
        $request->setLabel($labels)
431
            ->setWebshop($this->generalServiceType->getWebShopId())
432
            ->setIncludeMetaData($includeMetaData);
433
434
        $response = $this->generalServiceType->getExistingImageLabels($request);
435
436
        return $this->processResponse($response, $this->generalServiceType);
437
    }
438
}
439