Passed
Pull Request — master (#481)
by Artem
03:53
created

UpdateRefund::__construct()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 46
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 46
ccs 30
cts 30
cp 1
rs 8.9297
cc 6
nc 32
nop 1
crap 6
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\DocRefund;
24
25
use Amadeus\Client\RequestOptions\DocRefund\AddressOpt;
26
use Amadeus\Client\RequestOptions\DocRefund\CommissionOpt;
27
use Amadeus\Client\RequestOptions\DocRefund\FopOpt;
28
use Amadeus\Client\RequestOptions\DocRefund\FreeTextOpt;
29
use Amadeus\Client\RequestOptions\DocRefund\MonetaryData;
30
use Amadeus\Client\RequestOptions\DocRefund\Reference;
31
use Amadeus\Client\RequestOptions\DocRefund\RefundItinOpt;
32
use Amadeus\Client\RequestOptions\DocRefund\TaxData;
33
use Amadeus\Client\RequestOptions\DocRefund\Ticket as TicketOpt;
34
use Amadeus\Client\RequestOptions\DocRefundUpdateRefundOptions;
35
use Amadeus\Client\Struct\BaseWsMessage;
36
use Amadeus\Client\Struct\DocRefund\UpdateRefund\Commission;
37
use Amadeus\Client\Struct\DocRefund\UpdateRefund\DateTimeInformation;
38
use Amadeus\Client\Struct\DocRefund\UpdateRefund\FopGroup;
39
use Amadeus\Client\Struct\DocRefund\UpdateRefund\InteractiveFreeText;
40
use Amadeus\Client\Struct\DocRefund\UpdateRefund\MonetaryInformation;
41
use Amadeus\Client\Struct\DocRefund\UpdateRefund\PricingDetails;
42
use Amadeus\Client\Struct\DocRefund\UpdateRefund\ReferenceInformation;
43
use Amadeus\Client\Struct\DocRefund\UpdateRefund\RefundedItinerary;
44
use Amadeus\Client\Struct\DocRefund\UpdateRefund\RefundedRoute;
45
use Amadeus\Client\Struct\DocRefund\UpdateRefund\StructuredAddress;
46
use Amadeus\Client\Struct\DocRefund\UpdateRefund\TaxDetailsInformation;
47
use Amadeus\Client\Struct\DocRefund\UpdateRefund\Ticket;
48
use Amadeus\Client\Struct\DocRefund\UpdateRefund\TicketNumber;
49
use Amadeus\Client\Struct\DocRefund\UpdateRefund\TourInformation;
50
use Amadeus\Client\Struct\DocRefund\UpdateRefund\TravellerInformation;
51
use Amadeus\Client\Struct\DocRefund\UpdateRefund\TravellerPriorityInfo;
52
use Amadeus\Client\Struct\DocRefund\UpdateRefund\UserIdentification;
53
54
/**
55
 * DocRefund_UpdateRefund request structure
56
 *
57
 * @package Amadeus\Client\Struct\DocRefund
58
 * @author Dieter Devlieghere <[email protected]>
59
 */
60
class UpdateRefund extends BaseWsMessage
61
{
62
    /**
63
     * @var UpdateRefund\UserIdentification
64
     */
65
    public $userIdentification;
66
67
    /**
68
     * @var UpdateRefund\TicketNumber
69
     */
70
    public $ticketNumber;
71
72
    /**
73
     * @var UpdateRefund\DateTimeInformation[]
74
     */
75
    public $dateTimeInformation = [];
76
77
    /**
78
     * @var UpdateRefund\ReferenceInformation
79
     */
80
    public $referenceInformation;
81
82
    /**
83
     * @var UpdateRefund\TravellerInformation
84
     */
85
    public $travellerInformation;
86
87
    /**
88
     * @var UpdateRefund\Ticket[]
89
     */
90
    public $ticket = [];
91
92
    /**
93
     * @var UpdateRefund\TravellerPriorityInfo
94
     */
95
    public $travellerPriorityInfo;
96
97
    /**
98
     * @var UpdateRefund\MonetaryInformation
99
     */
100
    public $monetaryInformation;
101
102
    /**
103
     * @var UpdateRefund\PricingDetails
104
     */
105
    public $pricingDetails;
106
107
    /**
108
     * @var UpdateRefund\Commission
109
     */
110
    public $commission;
111
112
    /**
113
     * @var UpdateRefund\TaxDetailsInformation[]
114
     */
115
    public $taxDetailsInformation = [];
116
117
    /**
118
     * @var UpdateRefund\TourInformation
119
     */
120
    public $tourInformation;
121
122
    /**
123
     * @var UpdateRefund\InteractiveFreeText[]
124
     */
125
    public $interactiveFreeText = [];
126
127
    /**
128
     * @var UpdateRefund\FopGroup[]
129
     */
130
    public $fopGroup = [];
131
132
    /**
133
     * @var UpdateRefund\TransactionContext
134
     */
135
    public $transactionContext;
136
137
    /**
138
     * @var UpdateRefund\FirstAndLastSegmentDates
139
     */
140
    public $firstAndLastSegmentDates;
141
142
    /**
143
     * @var UpdateRefund\OriginAndDestination
144
     */
145
    public $originAndDestination;
146
147
    /**
148
     * @var UpdateRefund\RefundedItinerary[]
149
     */
150
    public $refundedItinerary = [];
151
152
    /**
153
     * @var UpdateRefund\RefundedRoute
154
     */
155
    public $refundedRoute;
156
157
    /**
158
     * @var UpdateRefund\StructuredAddress
159
     */
160
    public $structuredAddress;
161
162
    /**
163
     * @var UpdateRefund\FeeGroup
164
     */
165
    public $feeGroup;
166
167
    /**
168
     * UpdateRefund constructor.
169
     *
170
     * @param DocRefundUpdateRefundOptions $options
171
     */
172 30
    public function __construct(DocRefundUpdateRefundOptions $options)
173
    {
174 30
        if ($this->checkAnyNotEmpty($options->originator, $options->originatorId)) {
175 20
            $this->userIdentification = new UserIdentification(
176 20
                $options->originatorId,
177 20
                $options->originator
178 8
            );
179 8
        }
180
181 30
        if ($this->checkAnyNotEmpty($options->ticketNumber, $options->ticketType)) {
182 5
            $this->ticketNumber = new TicketNumber($options->ticketNumber, $options->ticketType);
183 2
        }
184
185 30
        $this->loadDateTimeInfo($options->refundDate, $options->ticketedDate);
186
187 30
        $this->loadReferences($options->references);
188
189 30
        if (!empty($options->passengerSurName)) {
190 10
            $this->travellerInformation = new TravellerInformation($options->passengerSurName);
191 4
        }
192
193 30
        $this->loadTickets($options->tickets);
194
195 30
        $this->loadPassengerPriority($options);
196
197 30
        $this->loadMonetaryInfo($options->monetaryData, $options->taxData);
198
199 30
        if (!empty($options->pricingTicketIndicator)) {
200 5
            $this->pricingDetails = new PricingDetails($options->pricingTicketIndicator);
201 2
        }
202
203 30
        $this->loadCommissions($options->commission);
204
205 30
        if (!empty($options->tourCode)) {
206 5
            $this->tourInformation = new TourInformation($options->tourCode);
207 2
        }
208
209 30
        $this->loadFreeText($options->freeText);
210
211 30
        $this->loadFop($options->formOfPayment);
212
213 30
        $this->loadRefundedItinerary($options->refundedItinerary);
214
215 30
        $this->loadRefundedRoute($options->refundedRouteStations);
216
217 30
        $this->loadAddress($options->address);
218 30
    }
219
220
    /**
221
     * @param \DateTime|null $refundDate
222
     * @param \DateTime|null $ticketedDate
223
     */
224 30
    protected function loadDateTimeInfo($refundDate, $ticketedDate)
225
    {
226 30
        if ($refundDate instanceof \DateTime) {
227 20
            $this->dateTimeInformation[] = new DateTimeInformation(
228 20
                DateTimeInformation::OPT_DATE_OF_REFUND,
229 8
                $refundDate
230 8
            );
231 8
        }
232
233 30
        if ($ticketedDate instanceof \DateTime) {
234 20
            $this->dateTimeInformation[] = new DateTimeInformation(
235 20
                DateTimeInformation::OPT_DATE_TICKETED,
236 8
                $ticketedDate
237 8
            );
238 8
        }
239 30
    }
240
241
    /**
242
     * @param Reference[] $references
243
     */
244 30
    protected function loadReferences($references)
245
    {
246 30
        if (!empty($references)) {
247 25
            $this->referenceInformation = new ReferenceInformation($references);
248 10
        }
249 30
    }
250
251
    /**
252
     * @param TicketOpt[] $tickets
253
     */
254 30
    protected function loadTickets($tickets)
255
    {
256 30
        foreach ($tickets as $ticket) {
257 20
            $this->ticket[] = new Ticket($ticket);
258 12
        }
259 30
    }
260
261
    /**
262
     * @param DocRefundUpdateRefundOptions $options
263
     */
264 30
    protected function loadPassengerPriority($options)
265
    {
266 30
        if ($this->checkAnyNotEmpty(
267 30
            $options->travellerPrioCompany,
268 30
            $options->travellerPrioDateOfJoining,
269 30
            $options->travellerPrioReference
270 12
        )
271 12
        ) {
272 15
            $this->travellerPriorityInfo = new TravellerPriorityInfo(
273 15
                $options->travellerPrioCompany,
274 15
                $options->travellerPrioDateOfJoining,
275 15
                $options->travellerPrioReference
276 6
            );
277 6
        }
278 30
    }
279
280
    /**
281
     * @param MonetaryData[] $monetaryData
282
     * @param TaxData[] $taxData
283
     */
284 30
    protected function loadMonetaryInfo($monetaryData, $taxData)
285
    {
286 30
        if (!empty($monetaryData)) {
287 20
            $this->monetaryInformation = new MonetaryInformation($monetaryData);
288 8
        }
289
290 30
        foreach ($taxData as $tax) {
291 20
            $this->taxDetailsInformation[] = new TaxDetailsInformation($tax);
292 12
        }
293 30
    }
294
295
    /**
296
     * @param CommissionOpt[] $commission
297
     */
298 30
    protected function loadCommissions($commission)
299
    {
300 30
        if (!empty($commission)) {
301 5
            $this->commission = new Commission($commission);
302 2
        }
303 30
    }
304
305
    /**
306
     * @param FreeTextOpt[] $freeText
307
     */
308 30
    protected function loadFreeText($freeText)
309
    {
310 30
        foreach ($freeText as $opt) {
311 5
            $this->interactiveFreeText[] = new InteractiveFreeText($opt);
312 12
        }
313 30
    }
314
315
    /**
316
     * @param FopOpt[] $formOfPayment
317
     */
318 30
    protected function loadFop($formOfPayment)
319
    {
320 30
        foreach ($formOfPayment as $fop) {
321 20
            $this->fopGroup[] = new FopGroup($fop);
322 12
        }
323 30
    }
324
325
    /**
326
     * @param RefundItinOpt[] $refundedItinerary
327
     */
328 30
    protected function loadRefundedItinerary($refundedItinerary)
329
    {
330 30
        foreach ($refundedItinerary as $itin) {
331 5
            $this->refundedItinerary[] = new RefundedItinerary($itin);
332 12
        }
333 30
    }
334
335
    /**
336
     * @param string[] $refundedRouteStations
337
     */
338 30
    protected function loadRefundedRoute($refundedRouteStations)
339
    {
340 30
        if (!empty($refundedRouteStations)) {
341 15
            $this->refundedRoute = new RefundedRoute($refundedRouteStations);
342 6
        }
343 30
    }
344
345
    /**
346
     * @param AddressOpt|null $address
347
     */
348 30
    protected function loadAddress($address)
349
    {
350 30
        if ($address instanceof AddressOpt) {
351 5
            $this->structuredAddress = new StructuredAddress($address);
352 2
        }
353 30
    }
354
}
355