PricePNRWithBookingClass13   F
last analyzed

Complexity

Total Complexity 61

Size/Duplication

Total Lines 636
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 61
eloc 246
c 3
b 0
f 0
dl 0
loc 636
ccs 289
cts 289
cp 1
rs 3.52

23 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A makeOverrideOptions() 0 11 3
A loadPastDate() 0 16 2
A makeOverrideOptionsWithCriteria() 0 14 3
A makePricingOptionFareFamilyOverride() 0 25 4
A loadExemptTaxes() 0 18 3
A makePricingOptionForCurrencyOverride() 0 13 2
A makePricingOptionFareBasisOverride() 0 24 3
A loadCorpNegoFare() 0 13 2
A loadFormOfPayment() 0 13 2
A loadTicketType() 0 13 2
A loadCabins() 0 14 3
A loadReferences() 0 13 2
A loadPricingLogic() 0 11 2
A loadAwardPricing() 0 12 1
A loadZapOffs() 0 21 4
A loadTaxes() 0 22 5
B loadPricingOptionsFromRequestOptions() 0 114 2
A loadPaxDiscount() 0 20 3
A loadPointOverrides() 0 27 3
A loadCorpUniFares() 0 15 3
A makePricingOptionForValidatingCarrier() 0 13 2
A loadObFees() 0 20 3

How to fix   Complexity   

Complex Class

Complex classes like PricePNRWithBookingClass13 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PricePNRWithBookingClass13, and based on these observations, apply Extract Interface, too.

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\Fare;
24
25
use Amadeus\Client\RequestCreator\MessageVersionUnsupportedException;
26
use Amadeus\Client\RequestOptions\Fare\PricePnr\AwardPricing;
27
use Amadeus\Client\RequestOptions\Fare\PricePnr\Cabin;
28
use Amadeus\Client\RequestOptions\Fare\PricePnr\ExemptTax;
29
use Amadeus\Client\RequestOptions\Fare\PricePnr\FareBasis;
30
use Amadeus\Client\RequestOptions\Fare\PricePnr\FareFamily;
31
use Amadeus\Client\RequestOptions\Fare\PricePnr\FormOfPayment;
32
use Amadeus\Client\RequestOptions\Fare\PricePnr\ObFee;
33
use Amadeus\Client\RequestOptions\Fare\PricePnr\PaxSegRef;
34
use Amadeus\Client\RequestOptions\Fare\PricePnr\Tax;
35
use Amadeus\Client\RequestOptions\Fare\PricePnr\ZapOff;
36
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
37
use Amadeus\Client\RequestOptions\FarePricePnrWithLowerFaresOptions as LowerFareOpt;
38
use Amadeus\Client\RequestOptions\FarePricePnrWithLowestFareOptions as LowestFareOpt;
39
use Amadeus\Client\RequestOptions\Fare\InformativePricing\PricingOptions as InformativePriceOpt;
40
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
41
use Amadeus\Client\Struct\Fare\PricePnr13\CriteriaDetails;
42
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
43
use Amadeus\Client\Struct\Fare\PricePnr13\DateInformation;
44
use Amadeus\Client\Struct\Fare\PricePnr13\FormOfPaymentInformation;
45
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentFlyerInformation;
46
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentTravellerDetails;
47
use Amadeus\Client\Struct\Fare\PricePnr13\LocationInformation;
48
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
49
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
50
use Amadeus\Client\Struct\Fare\PricePnr13\PenDisInformation;
51
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
52
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionKey;
53
use Amadeus\Client\Struct\Fare\PricePnr13\TaxData;
54
use Amadeus\Client\Struct\Fare\PricePnr13\TaxInformation;
55
56
/**
57
 * Fare_PricePNRWithBookingClass v 13 and higher structure
58
 *
59
 * @package Amadeus\Client\Struct\Fare
60
 * @author dieter <[email protected]>
61
 */
62
class PricePNRWithBookingClass13 extends BasePricingMessage
63
{
64
    /**
65
     * @var PricePnr13\PricingOptionGroup[]
66
     */
67
    public $pricingOptionGroup = [];
68
69
    /**
70
     * PricePNRWithBookingClass13 constructor.
71 120
     *
72
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt|InformativePriceOpt|null $options
73 120
     * @throws MessageVersionUnsupportedException
74 120
     */
75 48
    public function __construct($options)
76 120
    {
77
        if (!is_null($options)) {
78
            $this->pricingOptionGroup = $this->loadPricingOptionsFromRequestOptions($options);
79
        }
80
    }
81
82
    /**
83
     * Load an array of PricingOptionGroup objects from the Pricing request options.
84
     *
85
     * Extracted because this method is also used in the InformativePricingWithoutPnr messages.
86 155
     *
87
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt|InformativePriceOpt $options
88 155
     * @return PricingOptionGroup[]
89
     */
90 155
    public static function loadPricingOptionsFromRequestOptions($options)
91 155
    {
92 155
        $priceOptions = [];
93 62
94
        $priceOptions = self::mergeOptions(
95 155
            $priceOptions,
96 155
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
97 155
        );
98 62
99
        $priceOptions = self::mergeOptions(
100 155
            $priceOptions,
101 155
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
102 155
        );
103 62
104
        $priceOptions = self::mergeOptions(
105 155
            $priceOptions,
106 155
            self::makePricingOptionFareBasisOverride($options->pricingsFareBasis)
107 155
        );
108 62
109
        $priceOptions = self::mergeOptions(
110 155
            $priceOptions,
111 155
            self::makePricingOptionFareFamilyOverride($options->fareFamily)
0 ignored issues
show
Bug introduced by
It seems like $options->fareFamily can also be of type Amadeus\Client\RequestOp...e\PricePnr\FareFamily[]; however, parameter $fareFamily of Amadeus\Client\Struct\Fa...ionFareFamilyOverride() does only seem to accept string, 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

111
            self::makePricingOptionFareFamilyOverride(/** @scrutinizer ignore-type */ $options->fareFamily)
Loading history...
112 155
        );
113 62
114
        $priceOptions = self::mergeOptions(
115 155
            $priceOptions,
116 155
            self::loadCorpNegoFare($options->corporateNegoFare)
117 155
        );
118 62
119
        $priceOptions = self::mergeOptions(
120 155
            $priceOptions,
121 155
            self::loadCorpUniFares($options->corporateUniFares, $options->awardPricing)
122 155
        );
123 62
124
        $priceOptions = self::mergeOptions(
125 155
            $priceOptions,
126 155
            self::loadObFees($options->obFees, $options->obFeeRefs)
127 155
        );
128 62
129
        $priceOptions = self::mergeOptions(
130 155
            $priceOptions,
131 155
            self::loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs)
132 155
        );
133 155
134 155
        $priceOptions = self::mergeOptions(
135 62
            $priceOptions,
136 62
            self::loadPointOverrides(
137
                $options->pointOfSaleOverride,
138 155
                $options->pointOfTicketingOverride
139 155
            )
140 155
        );
141 62
142
        $priceOptions = self::mergeOptions(
143 155
            $priceOptions,
144 155
            self::loadPricingLogic($options->pricingLogic)
145 155
        );
146 62
147
        $priceOptions = self::mergeOptions(
148 155
            $priceOptions,
149 155
            self::loadTicketType($options->ticketType)
150 155
        );
151 62
152
        $priceOptions = self::mergeOptions(
153 155
            $priceOptions,
154 155
            self::loadTaxes($options->taxes)
155 155
        );
156 62
157
        $priceOptions = self::mergeOptions(
158 155
            $priceOptions,
159 155
            self::loadExemptTaxes($options->exemptTaxes)
160 155
        );
161 62
162
        $priceOptions = self::mergeOptions(
163
            $priceOptions,
164 155
            self::loadPastDate($options->pastDatePricing)
165 155
        );
166 155
167 62
168
        $priceOptions = self::mergeOptions(
169 155
            $priceOptions,
170 155
            self::loadFormOfPayment($options->formOfPayment)
171 155
        );
172 62
173
        $priceOptions = self::mergeOptions(
174 155
            $priceOptions,
175 155
            self::loadReferences($options->references)
176 155
        );
177 62
178
        $priceOptions = self::mergeOptions(
179 155
            $priceOptions,
180 155
            self::makeOverrideOptions($options->overrideOptions, $priceOptions)
181 155
        );
182 62
183
        $priceOptions = self::mergeOptions(
184
            $priceOptions,
185 155
            self::makeOverrideOptionsWithCriteria($options->overrideOptionsWithCriteria, $priceOptions)
186 30
        );
187 12
188
        $priceOptions = self::mergeOptions(
189 155
            $priceOptions,
190
            self::loadZapOffs($options->zapOff)
191
        );
192
193
        $priceOptions = self::mergeOptions(
194
            $priceOptions,
195
            self::loadCabins($options->cabins)
196
        );
197 155
198
        // All options processed, no options found:
199 155
        if (empty($priceOptions)) {
200
            $priceOptions[] = new PricingOptionGroup(PricingOptionKey::OPTION_NO_OPTION);
201 155
        }
202 40
203 40
        return $priceOptions;
204 16
    }
205 62
206
    /**
207 155
     * @param string[] $overrideOptions
208
     * @param PricingOptionGroup[] $priceOptions
209
     * @return PricingOptionGroup[]
210
     */
211
    protected static function makeOverrideOptions($overrideOptions, $priceOptions)
212
    {
213
        $opt = [];
214
215 155
        foreach ($overrideOptions as $overrideOption) {
216
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
217 155
                $opt[] = new PricingOptionGroup($overrideOption);
218
            }
219 155
        }
220 5
221 5
        return $opt;
222 2
    }
223 62
224
    /**
225 155
     * @param string[] $overrideOptionsWithCriteria
226
     * @param PricingOptionGroup[] $priceOptions
227
     * @return PricingOptionGroup[]
228
     */
229
    protected static function makeOverrideOptionsWithCriteria($overrideOptionsWithCriteria, $priceOptions)
230
    {
231
        $opt = [];
232 155
233
        foreach ($overrideOptionsWithCriteria as $overrideOptionWithCriteria) {
234 155
            if (!self::hasPricingGroup($overrideOptionWithCriteria["key"], $priceOptions)) {
235
                $opt[] = new PricingOptionGroup(
236 155
                    $overrideOptionWithCriteria['key'],
237 40
                    $overrideOptionWithCriteria['optionDetail'],
238
                );
239 40
            }
240
        }
241 40
242 16
        return $opt;
243
    }
244 155
245
    /**
246
     * @param string|null $validatingCarrier
247
     * @return PricePnr13\PricingOptionGroup[]
248
     */
249
    protected static function makePricingOptionForValidatingCarrier($validatingCarrier)
250
    {
251 155
        $opt = [];
252
253 155
        if ($validatingCarrier !== null) {
254
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);
255 155
256 40
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
257
258 40
            $opt[] = $po;
259
        }
260 40
261 16
        return $opt;
262
    }
263 155
264
    /**
265
     * @param string|null $currency
266
     * @return PricePnr13\PricingOptionGroup[]
267
     */
268
    protected static function makePricingOptionForCurrencyOverride($currency)
269
    {
270
        $opt = [];
271 155
272
        if ($currency !== null) {
273 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
274
275 155
            $po->currency = new Currency($currency);
276 155
277 20
            $opt[] = $po;
278
        }
279
280 20
        return $opt;
281 20
    }
282 8
283
284
    /**
285 20
     * @param FareBasis[] $pricingsFareBasis
286 20
     * @return PricePnr13\PricingOptionGroup[]
287 20
     */
288 8
    protected static function makePricingOptionFareBasisOverride($pricingsFareBasis)
289
    {
290 20
        $opt = [];
291 62
292 62
        if ($pricingsFareBasis !== null) {
0 ignored issues
show
introduced by
The condition $pricingsFareBasis !== null is always true.
Loading history...
293
            foreach ($pricingsFareBasis as $pricingFareBasis) {
294 155
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
295
296
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
297
                $po->optionDetail = new OptionDetail(
298
                    $pricingFareBasis->fareBasisPrimaryCode.$pricingFareBasis->fareBasisCode
0 ignored issues
show
Deprecated Code introduced by
The property Amadeus\Client\RequestOp...::$fareBasisPrimaryCode has been deprecated: put the full fare basis in $this->fareBasisCode ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

298
                    /** @scrutinizer ignore-deprecated */ $pricingFareBasis->fareBasisPrimaryCode.$pricingFareBasis->fareBasisCode

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
299
                );
300
301
                //Support for legacy segmentReference to be removed when breaking BC:
302
                $po->paxSegTstReference = new PaxSegTstReference(
303 155
                    $pricingFareBasis->references,
304
                    $pricingFareBasis->segmentReference
0 ignored issues
show
Deprecated Code introduced by
The property Amadeus\Client\RequestOp...asis::$segmentReference has been deprecated: use $this->references instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

304
                    /** @scrutinizer ignore-deprecated */ $pricingFareBasis->segmentReference

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
305 155
                );
306
307 155
                $opt[] = $po;
308 5
            }
309 5
        }
310
311 5
        return $opt;
312 2
    }
313
314 155
    /**
315
     * Load fare-family pricing option and return it.
316
     *
317
     * @param string $fareFamily input fare-family, e.g. "CLASSIC"
318
     * @return PricePnr13\PricingOptionGroup[]
319
     */
320
    protected static function makePricingOptionFareFamilyOverride($fareFamily)
321
    {
322
        $opt = [];
323 155
324
        if ($fareFamily !== null) {
0 ignored issues
show
introduced by
The condition $fareFamily !== null is always true.
Loading history...
325 155
            if (is_array($fareFamily)) {
0 ignored issues
show
introduced by
The condition is_array($fareFamily) is always false.
Loading history...
326
                /**
327 155
                 * @var FareFamily $item
328 5
                 */
329
                foreach ($fareFamily as $item) {
330 5
                    $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
331
                    $po->optionDetail = new OptionDetail([['FF' => $item->fareFamily]]);
332 5
                    $po->paxSegTstReference = new PaxSegTstReference($item->paxSegRefs);
333 2
334
                    $opt[] = $po;
335 155
                }
336
            } else {
337
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
338
                $po->optionDetail = new OptionDetail([['FF' => $fareFamily]]);
339
340
                $opt[] = $po;
341
            }
342
        }
343
344
        return $opt;
345 155
    }
346
347 155
    /**
348
     * Load corporate negofare
349 155
     *
350 10
     * @param string|null $corporateNegoFare
351 10
     * @return PricingOptionGroup[]
352 10
     */
353
    protected static function loadCorpNegoFare($corporateNegoFare)
354 10
    {
355 5
        $opt = [];
356 2
357 4
        if ($corporateNegoFare !== null) {
358
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_NEGOTIATED_FARES);
359 155
360
            $po->optionDetail = new OptionDetail($corporateNegoFare);
361
362
            $opt[] = $po;
363
        }
364
365
        return $opt;
366 5
    }
367
368 5
    /**
369
     * Load corporate unifares
370 5
     *
371
     * @param string[] $corporateUniFares
372 5
     * @param AwardPricing|null $awardPricing
373 5
     * @return PricingOptionGroup[]
374 5
     */
375 2
    protected static function loadCorpUniFares($corporateUniFares, $awardPricing)
376
    {
377 5
        $opt = [];
378
379
        if (!empty($corporateUniFares)) {
380
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
381
            $po->optionDetail = new OptionDetail($corporateUniFares);
382
            $opt[] = $po;
383
384
            if (!empty($awardPricing)) {
385
                $opt[] = self::loadAwardPricing($awardPricing);
386
            }
387 155
        }
388
389 155
        return $opt;
390
    }
391 155
392 5
    /**
393
     * @param AwardPricing $awardPricing
394 5
     * @return PricingOptionGroup
395 5
     */
396 2
    protected static function loadAwardPricing($awardPricing)
397 2
    {
398
        $po = new PricingOptionGroup(PricingOptionKey::OPTION_AWARD_PRICING);
399 5
400 5
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
401 2
402
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
403 5
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
404 2
            $awardPricing->tierLevel
405
        );
406 155
407
        return $po;
408
    }
409
410
    /**
411
     * Load OB Fees
412
     *
413
     * @param ObFee[] $obFees
414 155
     * @param PaxSegRef[] $obFeeRefs
415
     * @return PricingOptionGroup[]
416 155
     */
417
    protected static function loadObFees($obFees, $obFeeRefs)
418 155
    {
419 20
        $opt = [];
420
421 20
        if (!empty($obFees)) {
422 20
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_OB_FEES);
423 8
424 8
            $po->penDisInformation = new PenDisInformation(
425
                PenDisInformation::QUAL_OB_FEES,
426 20
                $obFees
427 20
            );
428 8
429
            if (!empty($obFeeRefs)) {
430 20
                $po->paxSegTstReference = new PaxSegTstReference($obFeeRefs);
431 8
            }
432
433 155
            $opt[] = $po;
434
        }
435
436
        return $opt;
437
    }
438
439
    /**
440
     * @param string[] $paxDiscount
441 155
     * @param PaxSegRef[] $paxDiscountCodeRefs
442
     * @return PricingOptionGroup[]
443 155
     */
444
    protected static function loadPaxDiscount($paxDiscount, $paxDiscountCodeRefs)
445 155
    {
446 5
        $opt = [];
447
448 5
        if (!empty($paxDiscount)) {
449 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
450 2
451 2
            $po->penDisInformation = new PenDisInformation(
452
                PenDisInformation::QUAL_DISCOUNT,
453 5
                $paxDiscount
454 2
            );
455
456 155
            if (!empty($paxDiscountCodeRefs)) {
457 5
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
458
            }
459 5
460 5
            $opt[] = $po;
461 2
        }
462 2
463
        return $opt;
464 5
    }
465 2
466
    /**
467 155
     * @param string|null $posOverride
468
     * @param string|null $potOverride
469
     * @return PricingOptionGroup[]
470
     */
471
    protected static function loadPointOverrides($posOverride, $potOverride)
472
    {
473
        $opt = [];
474 155
475
        if (!empty($posOverride)) {
476 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
477
478 155
            $po->locationInformation = new LocationInformation(
479 5
                LocationInformation::TYPE_POINT_OF_SALE,
480 5
                $posOverride
481 5
            );
482 2
483
            $opt[] = $po;
484 155
        }
485
486
        if (!empty($potOverride)) {
487
            $po2 = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
488
489
            $po2->locationInformation = new LocationInformation(
490
                LocationInformation::TYPE_POINT_OF_TICKETING,
491 155
                $potOverride
492
            );
493 155
494
            $opt[] = $po2;
495 155
        }
496 5
497
        return $opt;
498 5
    }
499
500 5
    /**
501 2
     * @param string|null $pricingLogic
502
     * @return PricingOptionGroup[]
503 155
     */
504
    protected static function loadPricingLogic($pricingLogic)
505
    {
506
        $opt = [];
507
508
        if (!empty($pricingLogic)) {
509
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PRICING_LOGIC);
510 155
            $po->optionDetail = new OptionDetail($pricingLogic);
511
            $opt[] = $po;
512 155
        }
513
514 155
        return $opt;
515 5
    }
516
517 5
    /**
518 5
     * @param string|null $ticketType
519 5
     * @return PricingOptionGroup[]
520
     */
521 5
    protected static function loadTicketType($ticketType)
522 5
    {
523 5
        $opt = [];
524 4
525 2
        if (!empty($ticketType)) {
526 2
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_TICKET_TYPE);
527 2
528 5
            $po->optionDetail = new OptionDetail($ticketType);
529 2
530
            $opt[] = $po;
531 155
        }
532
533
        return $opt;
534
    }
535
536
    /**
537
     * @param Tax[] $taxes
538 155
     * @return PricingOptionGroup[]
539
     */
540 155
    protected static function loadTaxes($taxes)
541
    {
542 155
        $opt = [];
543 5
544
        if (!empty($taxes)) {
545 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_ADD_TAX);
546 5
547 5
            foreach ($taxes as $tax) {
548 5
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
549 2
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
550 2
551
                $po->taxInformation[] = new TaxInformation(
552 5
                    $tax->countryCode,
553 2
                    $tax->taxNature,
554
                    $qualifier,
555 155
                    $rate
556
                );
557
            }
558
            $opt[] = $po;
559
        }
560
561
        return $opt;
562 155
    }
563
564 155
    /**
565
     * @param ExemptTax[] $exemptTaxes
566 155
     * @return PricingOptionGroup[]
567 5
     */
568
    protected static function loadExemptTaxes($exemptTaxes)
569 5
    {
570 5
        $opt = [];
571 2
572 2
        if (!empty($exemptTaxes)) {
573
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_EXEMPT_FROM_TAX);
574 5
575 2
            foreach ($exemptTaxes as $tax) {
576
                $po->taxInformation[] = new TaxInformation(
577 155
                    $tax->countryCode,
578
                    $tax->taxNature
579
                );
580
            }
581
582
            $opt[] = $po;
583
        }
584
585 155
        return $opt;
586
    }
587 155
588
    /**
589 155
     * @param \DateTime|null $pastDate
590 5
     * @return PricingOptionGroup[]
591
     */
592 5
    protected static function loadPastDate($pastDate)
593
    {
594 5
        $opt = [];
595 2
596
        if ($pastDate instanceof \DateTime) {
597 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAST_DATE_PRICING);
598
599
            $po->dateInformation = new DateInformation(
600
                DateInformation::OPT_DATE_OVERRIDE,
601
                $pastDate
602
            );
603
604 155
            $opt[] = $po;
605
        }
606 155
607
        return $opt;
608 155
    }
609 5
610
611 5
    /**
612
     * @param FormOfPayment[] $formOfPayment
613 5
     * @return PricingOptionGroup[]
614 2
     */
615
    protected static function loadFormOfPayment($formOfPayment)
616 155
    {
617
        $opt = [];
618
619
        if (!empty($formOfPayment)) {
620
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FORM_OF_PAYMENT);
621
622
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
623
624
            $opt[] = $po;
625
        }
626
627
        return $opt;
628
    }
629
630
    /**
631
     * @param PaxSegRef[] $references
632
     * @return PricingOptionGroup[]
633
     */
634
    protected static function loadReferences($references)
635
    {
636
        $opt = [];
637
638
        if (!empty($references)) {
639
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAX_SEGMENT_TST_SELECTION);
640
641
            $po->paxSegTstReference = new PaxSegTstReference($references);
642
643
            $opt[] = $po;
644
        }
645
646
        return $opt;
647
    }
648
649
    /**
650
     * Load ZAP-Off
651
     *
652
     * @param ZapOff[] $zapOffs
653
     * @return PricingOptionGroup[]
654
     */
655
    protected static function loadZapOffs($zapOffs)
656
    {
657
        $opt = [];
658
        if (!empty($zapOffs)) {
659
            foreach ($zapOffs as $zapOff) {
660
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_ZAP_OFF);
661
662
                $po->penDisInformation = new PenDisInformation(
663
                    PenDisInformation::QUAL_ZAPOFF_DISCOUNT,
664
                    [$zapOff]
665
                );
666
667
                if (!empty($zapOff->paxSegRefs)) {
668
                    $po->paxSegTstReference = new PaxSegTstReference($zapOff->paxSegRefs);
669
                }
670
671
                $opt[] = $po;
672
            }
673
        }
674
675
        return $opt;
676
    }
677
678
    /**
679
     * Load Cabins
680
     *
681
     * @param Cabin[] $cabins
682
     * @return array
683
     */
684
    protected static function loadCabins($cabins)
685
    {
686
        $opt = [];
687
        if (!empty($cabins)) {
688
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CABIN);
689
            $criteriaDetails = [];
690
            foreach ($cabins as $cabin) {
691
                $criteriaDetails[] = new CriteriaDetails($cabin->cabinType, $cabin->cabinCode);
692
            }
693
            $po->optionDetail = new OptionDetail($criteriaDetails);
694
            $opt[] = $po;
695
        }
696
697
        return $opt;
698
    }
699
}
700