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

DocumentService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 118
Duplicated Lines 41.53 %

Importance

Changes 0
Metric Value
wmc 6
dl 49
loc 118
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProofOfDelivery() 0 12 1
A generateAdditionalPdfDocument() 13 13 1
A generatePdfCustomsDocuments() 20 20 2
A generateAdditionalImageDocument() 13 13 1
A __construct() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Etrias\PaazlConnector\Processor\Processor;
16
use Etrias\PaazlConnector\ServiceType\Service as GeneralServiceType;
17
use Etrias\PaazlConnector\StructType\GenerateAdditionalImageDocumentResponse;
18
use Etrias\PaazlConnector\StructType\GenerateAdditionalPdfDocumentRequest;
19
use Etrias\PaazlConnector\StructType\GenerateAdditionalPdfDocumentResponse;
20
use Etrias\PaazlConnector\StructType\GeneratePdfCustomsDocumentsRequest;
21
use Etrias\PaazlConnector\StructType\GeneratePdfCustomsDocumentsResponse;
22
use Etrias\PaazlConnector\StructType\OrderType;
23
use Etrias\PaazlConnector\StructType\ProofOfDeliveryRequest;
24
use Etrias\PaazlConnector\StructType\ProofOfDeliveryResponse;
25
26
class DocumentService
27
{
28
    use Processor;
29
30
    /**
31
     * @var SecurityServiceInterface
32
     */
33
    protected $securityService;
34
    /**
35
     * @var GeneralServiceType
36
     */
37
    protected $generalServiceType;
38
39
    /**
40
     * DocumentService constructor.
41
     *
42
     * @param GeneralServiceType       $generalServiceType
43
     * @param SecurityServiceInterface $securityService
44
     */
45
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
46
    {
47
        $this->securityService = $securityService;
48
        $this->generalServiceType = $generalServiceType;
49
    }
50
51
    /**
52
     * @param $orderReference
53
     * @param $barcode
54
     * @param $documentType
55
     * @param null $printer
56
     * @param null $targetWebShop
57
     *
58
     * @return GenerateAdditionalPdfDocumentResponse
59
     */
60 View Code Duplication
    public function generateAdditionalPdfDocument($orderReference, $barcode, $documentType, $printer = null, $targetWebShop = null)
61
    {
62
        $request = new GenerateAdditionalPdfDocumentRequest($printer);
63
        $request->setHash($this->securityService->getHash($orderReference))
64
            ->setWebshop($this->generalServiceType->getWebShopId())
65
            ->setTargetWebshop($targetWebShop)
66
            ->setOrderReference($orderReference)
67
            ->setBarcode($barcode)
68
            ->setDocumentType($documentType);
69
70
        $response = $this->generalServiceType->generateAdditionalPdfDocument($request);
71
72
        return $this->processResponse($response, $this->generalServiceType);
73
    }
74
75
    /**
76
     * @param $orderReference
77
     * @param $barcode
78
     * @param $documentType
79
     * @param null $targetWebShop
80
     *
81
     * @return GenerateAdditionalImageDocumentResponse
82
     */
83 View Code Duplication
    public function generateAdditionalImageDocument($orderReference, $barcode, $documentType, $targetWebShop = null)
84
    {
85
        $request = new GenerateAdditionalPdfDocumentRequest();
86
        $request->setHash($this->securityService->getHash($orderReference))
87
            ->setWebshop($this->generalServiceType->getWebShopId())
88
            ->setTargetWebshop($targetWebShop)
89
            ->setOrderReference($orderReference)
90
            ->setBarcode($barcode)
91
            ->setDocumentType($documentType);
92
93
        $response = $this->generalServiceType->generateAdditionalImageDocument($request);
94
95
        return $this->processResponse($response, $this->generalServiceType);
96
    }
97
98
    /**
99
     * @param array $orderReferences
100
     * @param $targetWebShop
101
     *
102
     * @return GeneratePdfCustomsDocumentsResponse
103
     */
104 View Code Duplication
    public function generatePdfCustomsDocuments(array $orderReferences, $targetWebShop = null)
105
    {
106
        $orders = [];
107
108
        foreach ($orderReferences as $orderReference) {
109
            $orders[] = new OrderType(
110
                $this->securityService->getHash($orderReference),
111
                $targetWebShop,
112
                $orderReference
113
            );
114
        }
115
116
        $request = new GeneratePdfCustomsDocumentsRequest(
117
            $this->generalServiceType->getWebShopId(),
118
            $orders
119
        );
120
121
        $response = $this->generalServiceType->generatePdfCustomsDocuments($request);
122
123
        return $this->processResponse($response, $this->generalServiceType);
124
    }
125
126
    /**
127
     * @param $barcode
128
     * @param null $targetWebShop
129
     *
130
     * @return ProofOfDeliveryResponse
131
     */
132
    public function getProofOfDelivery($barcode, $targetWebShop = null)
133
    {
134
        $request = new ProofOfDeliveryRequest(
135
            $this->securityService->getHash($barcode),
136
            $this->generalServiceType->getWebShopId(),
137
            $targetWebShop,
138
            $barcode
139
        );
140
141
        $response = $this->generalServiceType->proofOfDelivery($request);
142
143
        return $this->processResponse($response, $this->generalServiceType);
144
    }
145
}
146