Passed
Push — master ( 14ed4f...95f9a6 )
by Andrew
20:11
created

PricePNRWithBookingClass13::loadZapOffs()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 22

Duplication

Lines 14
Ratio 63.64 %

Importance

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

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

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

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