Passed
Push — master ( a8f3a0...0e6cb9 )
by C.
02:17
created

PickupService::getPickupRequestStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
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\AddressType;
19
use Etrias\PaazlConnector\StructType\CancelPickupRequestResponse;
20
use Etrias\PaazlConnector\StructType\CreatePickupRequestRequest;
21
use Etrias\PaazlConnector\StructType\CreatePickupRequestResponse;
22
use Etrias\PaazlConnector\StructType\PickupRequestDetailsResponse;
23
use Etrias\PaazlConnector\StructType\PickupRequestOptionsRequest;
24
use Etrias\PaazlConnector\StructType\PickupRequestQueryType;
25
use Etrias\PaazlConnector\StructType\PickupRequestStatusResponse;
26
use InvalidArgumentException;
27
28
class PickupService
29
{
30
    use Processor;
31
32
    /**
33
     * @var SecurityServiceInterface
34
     */
35
    protected $securityService;
36
    /**
37
     * @var GeneralServiceType
38
     */
39
    protected $generalServiceType;
40
41
    /**
42
     * DocumentService constructor.
43
     *
44
     * @param GeneralServiceType       $generalServiceType
45
     * @param SecurityServiceInterface $securityService
46
     */
47
    public function __construct(GeneralServiceType $generalServiceType, SecurityServiceInterface $securityService)
48
    {
49
        $this->securityService = $securityService;
50
        $this->generalServiceType = $generalServiceType;
51
    }
52
53
    /**
54
     * @param $internalReference
55
     * @param null $pickupCountry
56
     * @param null $deliveryCountry
57
     * @param null $targetWebShop
58
     *
59
     * @return PickupRequestDetailsResponse
60
     */
61 View Code Duplication
    public function getPickupRequestOptions($internalReference, $pickupCountry = null, $deliveryCountry = null, $targetWebShop = null)
62
    {
63
        $request = new PickupRequestOptionsRequest(
64
            $this->securityService->getHash($internalReference),
65
            $this->generalServiceType->getWebShopId(),
66
            $targetWebShop,
67
            $internalReference,
68
            $pickupCountry,
69
            $deliveryCountry
70
        );
71
72
        $response = $this->generalServiceType->pickupRequestOptions($request);
73
74
        return $this->processResponse($response, $this->generalServiceType);
75
    }
76
77
    /**
78
     * @param $internalReference
79
     * @param $pickupRequestOption
80
     * @param $pieceCount
81
     * @param DateTime $pickupWindowStart
82
     * @param DateTime $pickupWindowEnd
83
     * @param $pickupCompanyName
84
     * @param $pickupContactName
85
     * @param $pickupName
86
     * @param AddressType $pickupAddress
87
     * @param $pickupPhoneNumber
88
     * @param null             $pickupEmailAddress
89
     * @param AddressType|null $deliveryAddress
90
     * @param null             $deliveryEmailAddress
91
     * @param null             $additionalInstruction
92
     * @param null             $orderReference
93
     * @param null             $contract
94
     * @param null             $targetWebShop
95
     *
96
     * @return CreatePickupRequestResponse
97
     */
98
    public function createPickupRequest(
99
        $internalReference,
100
        $pickupRequestOption,
101
        $pieceCount,
102
        DateTime $pickupWindowStart,
103
        DateTime $pickupWindowEnd,
104
        $pickupCompanyName,
105
        $pickupContactName,
106
        $pickupName,
107
        AddressType $pickupAddress,
108
        $pickupPhoneNumber,
109
        $pickupEmailAddress = null,
110
        AddressType $deliveryAddress = null,
111
        $deliveryEmailAddress = null,
112
        $additionalInstruction = null,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $additionalInstruction 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...
113
        $orderReference = null,
114
        $contract = null,
115
        $targetWebShop = null
116
    ) {
117
        if ($pickupWindowStart->format('Y-m-d') !== $pickupWindowEnd->format('Y-m-d')) {
118
            throw new InvalidArgumentException('pickupWindowStart and pickupWindowEnd should be on the same day');
119
        }
120
121
        $request = new CreatePickupRequestRequest(
122
            $this->securityService->getHash($internalReference),
123
            $this->generalServiceType->getWebShopId(),
124
            $targetWebShop,
125
            $internalReference,
126
            $contract,
127
            $pickupRequestOption,
128
            $orderReference,
129
            $pieceCount,
130
            $pickupWindowStart->format('Y-m-d'),
131
            $pickupWindowStart->format('H:i:s'),
132
            $pickupWindowEnd->format('H:i:s'),
133
            $pickupCompanyName,
134
            $pickupContactName,
135
            $pickupName,
136
            $pickupAddress,
137
            $pickupPhoneNumber,
138
            $pickupEmailAddress,
139
            $deliveryAddress,
140
            $deliveryEmailAddress,
141
            $additionalInstruction
142
        );
143
144
        $response = $this->generalServiceType->createPickupRequest($request);
145
146
        return $this->processResponse($response, $this->generalServiceType);
147
    }
148
149
    /**
150
     * @param $internalReference
151
     * @param $distributor
152
     * @param $externalReference
153
     * @param null $targetWebShop
154
     *
155
     * @return PickupRequestDetailsResponse
156
     */
157
    public function getPickupRequestDetails($internalReference, $distributor, $externalReference, $targetWebShop = null)
158
    {
159
        $request = new PickupRequestQueryType(
160
            $this->securityService->getHash($internalReference),
161
            $this->generalServiceType->getWebShopId(),
162
            $targetWebShop,
163
            $internalReference,
164
            $distributor,
165
            $externalReference
166
        );
167
168
        $response = $this->generalServiceType->pickupRequestDetails($request);
169
170
        return $this->processResponse($response, $this->generalServiceType);
171
    }
172
173
    /**
174
     * @param $internalReference
175
     * @param $distributor
176
     * @param $externalReference
177
     * @param null $targetWebShop
178
     *
179
     * @return PickupRequestStatusResponse
180
     */
181
    public function getPickupRequestStatus($internalReference, $distributor, $externalReference, $targetWebShop = null)
182
    {
183
        $request = new PickupRequestQueryType(
184
            $this->securityService->getHash($internalReference),
185
            $this->generalServiceType->getWebShopId(),
186
            $targetWebShop,
187
            $internalReference,
188
            $distributor,
189
            $externalReference
190
        );
191
192
        $response = $this->generalServiceType->pickupRequestStatus($request);
193
194
        return $this->processResponse($response, $this->generalServiceType);
195
    }
196
197
    /**
198
     * @param $internalReference
199
     * @param $distributor
200
     * @param $externalReference
201
     * @param null $targetWebShop
202
     *
203
     * @return CancelPickupRequestResponse
204
     */
205
    public function cancelPickupRequest($internalReference, $distributor, $externalReference, $targetWebShop = null)
206
    {
207
        $request = new PickupRequestQueryType(
208
            $this->securityService->getHash($internalReference),
209
            $this->generalServiceType->getWebShopId(),
210
            $targetWebShop,
211
            $internalReference,
212
            $distributor,
213
            $externalReference
214
        );
215
216
        $response = $this->generalServiceType->cancelPickupRequest($request);
217
218
        return $this->processResponse($response, $this->generalServiceType);
219
    }
220
}
221