Passed
Push — master ( 6493d0...b49e1f )
by Dieter
10:05
created

PricePNRWithBookingClass13::loadCabins()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 9.7666
cc 3
nc 2
nop 1
crap 12
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 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...
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 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...
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($overrideOptionWithCriteria["key"], $overrideOptionWithCriteria["optionDetail"]);
236 155
            }
237 40
        }
238
239 40
        return $opt;
240
    }
241 40
242 16
    /**
243
     * @param string|null $validatingCarrier
244 155
     * @return PricePnr13\PricingOptionGroup[]
245
     */
246 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...
247
    {
248
        $opt = [];
249
250
        if ($validatingCarrier !== null) {
251 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);
252
253 155
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
254
255 155
            $opt[] = $po;
256 40
        }
257
258 40
        return $opt;
259
    }
260 40
261 16
    /**
262
     * @param string|null $currency
263 155
     * @return PricePnr13\PricingOptionGroup[]
264
     */
265 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...
266
    {
267
        $opt = [];
268
269
        if ($currency !== null) {
270
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
271 155
272
            $po->currency = new Currency($currency);
273 155
274
            $opt[] = $po;
275 155
        }
276 155
277 20
        return $opt;
278
    }
279
280 20
281 20
    /**
282 8
     * @param FareBasis[] $pricingsFareBasis
283
     * @return PricePnr13\PricingOptionGroup[]
284
     */
285 20 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...
286 20
    {
287 20
        $opt = [];
288 8
289
        if ($pricingsFareBasis !== null) {
290 20
            foreach ($pricingsFareBasis as $pricingFareBasis) {
291 62
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
292 62
293
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
294 155
                $po->optionDetail = new OptionDetail(
295
                    $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...
296
                );
297
298
                //Support for legacy segmentReference to be removed when breaking BC:
299
                $po->paxSegTstReference = new PaxSegTstReference(
300
                    $pricingFareBasis->references,
301
                    $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...
302
                );
303 155
304
                $opt[] = $po;
305 155
            }
306
        }
307 155
308 5
        return $opt;
309 5
    }
310
311 5
    /**
312 2
     * Load fare-family pricing option and return it.
313
     *
314 155
     * @param string $fareFamily input fare-family, e.g. "CLASSIC"
315
     * @return PricePnr13\PricingOptionGroup[]
316
     */
317
    protected static function makePricingOptionFareFamilyOverride($fareFamily)
318
    {
319
        $opt = [];
320
321
        if ($fareFamily !== null) {
322
            if (is_array($fareFamily)) {
323 155
                /**
324
                 * @var FareFamily $item
325 155
                 */
326 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...
327 155
                    $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
328 5
                    $po->optionDetail = new OptionDetail([['FF' => $item->fareFamily]]);
329
                    $po->paxSegTstReference = new PaxSegTstReference($item->paxSegRefs);
330 5
331
                    $opt[] = $po;
332 5
                }
333 2
            } else {
334
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
335 155
                $po->optionDetail = new OptionDetail([['FF' => $fareFamily]]);
336
337
                $opt[] = $po;
338
            }
339
        }
340
341
        return $opt;
342
    }
343
344
    /**
345 155
     * Load corporate negofare
346
     *
347 155
     * @param string|null $corporateNegoFare
348
     * @return PricingOptionGroup[]
349 155
     */
350 10
    protected static function loadCorpNegoFare($corporateNegoFare)
351 10
    {
352 10
        $opt = [];
353
354 10
        if ($corporateNegoFare !== null) {
355 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_NEGOTIATED_FARES);
356 2
357 4
            $po->optionDetail = new OptionDetail($corporateNegoFare);
358
359 155
            $opt[] = $po;
360
        }
361
362
        return $opt;
363
    }
364
365
    /**
366 5
     * Load corporate unifares
367
     *
368 5
     * @param string[] $corporateUniFares
369
     * @param AwardPricing|null $awardPricing
370 5
     * @return PricingOptionGroup[]
371
     */
372 5
    protected static function loadCorpUniFares($corporateUniFares, $awardPricing)
373 5
    {
374 5
        $opt = [];
375 2
376
        if (!empty($corporateUniFares)) {
377 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
378
            $po->optionDetail = new OptionDetail($corporateUniFares);
379
            $opt[] = $po;
380
381
            if (!empty($awardPricing)) {
382
                $opt[] = self::loadAwardPricing($awardPricing);
383
            }
384
        }
385
386
        return $opt;
387 155
    }
388
389 155
    /**
390
     * @param AwardPricing $awardPricing
391 155
     * @return PricingOptionGroup
392 5
     */
393 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...
394 5
    {
395 5
        $po = new PricingOptionGroup(PricingOptionKey::OPTION_AWARD_PRICING);
396 2
397 2
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
398
399 5
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
400 5
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
401 2
            $awardPricing->tierLevel
402
        );
403 5
404 2
        return $po;
405
    }
406 155
407
    /**
408
     * Load OB Fees
409
     *
410
     * @param ObFee[] $obFees
411
     * @param PaxSegRef[] $obFeeRefs
412
     * @return PricingOptionGroup[]
413
     */
414 155 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...
415
    {
416 155
        $opt = [];
417
418 155
        if (!empty($obFees)) {
419 20
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_OB_FEES);
420
421 20
            $po->penDisInformation = new PenDisInformation(
422 20
                PenDisInformation::QUAL_OB_FEES,
423 8
                $obFees
424 8
            );
425
426 20
            if (!empty($obFeeRefs)) {
427 20
                $po->paxSegTstReference = new PaxSegTstReference($obFeeRefs);
428 8
            }
429
430 20
            $opt[] = $po;
431 8
        }
432
433 155
        return $opt;
434
    }
435
436
    /**
437
     * @param string[] $paxDiscount
438
     * @param PaxSegRef[] $paxDiscountCodeRefs
439
     * @return PricingOptionGroup[]
440
     */
441 155 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...
442
    {
443 155
        $opt = [];
444
445 155
        if (!empty($paxDiscount)) {
446 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
447
448 5
            $po->penDisInformation = new PenDisInformation(
449 5
                PenDisInformation::QUAL_DISCOUNT,
450 2
                $paxDiscount
451 2
            );
452
453 5
            if (!empty($paxDiscountCodeRefs)) {
454 2
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
455
            }
456 155
457 5
            $opt[] = $po;
458
        }
459 5
460 5
        return $opt;
461 2
    }
462 2
463
    /**
464 5
     * @param string|null $posOverride
465 2
     * @param string|null $potOverride
466
     * @return PricingOptionGroup[]
467 155
     */
468 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...
469
    {
470
        $opt = [];
471
472
        if (!empty($posOverride)) {
473
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
474 155
475
            $po->locationInformation = new LocationInformation(
476 155
                LocationInformation::TYPE_POINT_OF_SALE,
477
                $posOverride
478 155
            );
479 5
480 5
            $opt[] = $po;
481 5
        }
482 2
483
        if (!empty($potOverride)) {
484 155
            $po2 = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
485
486
            $po2->locationInformation = new LocationInformation(
487
                LocationInformation::TYPE_POINT_OF_TICKETING,
488
                $potOverride
489
            );
490
491 155
            $opt[] = $po2;
492
        }
493 155
494
        return $opt;
495 155
    }
496 5
497
    /**
498 5
     * @param string|null $pricingLogic
499
     * @return PricingOptionGroup[]
500 5
     */
501 2 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...
502
    {
503 155
        $opt = [];
504
505
        if (!empty($pricingLogic)) {
506
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PRICING_LOGIC);
507
            $po->optionDetail = new OptionDetail($pricingLogic);
508
            $opt[] = $po;
509
        }
510 155
511
        return $opt;
512 155
    }
513
514 155
    /**
515 5
     * @param string|null $ticketType
516
     * @return PricingOptionGroup[]
517 5
     */
518 5 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...
519 5
    {
520
        $opt = [];
521 5
522 5
        if (!empty($ticketType)) {
523 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_TICKET_TYPE);
524 4
525 2
            $po->optionDetail = new OptionDetail($ticketType);
526 2
527 2
            $opt[] = $po;
528 5
        }
529 2
530
        return $opt;
531 155
    }
532
533
    /**
534
     * @param Tax[] $taxes
535
     * @return PricingOptionGroup[]
536
     */
537 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...
538 155
    {
539
        $opt = [];
540 155
541
        if (!empty($taxes)) {
542 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_ADD_TAX);
543 5
544
            foreach ($taxes as $tax) {
545 5
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
546 5
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
547 5
548 5
                $po->taxInformation[] = new TaxInformation(
549 2
                    $tax->countryCode,
550 2
                    $tax->taxNature,
551
                    $qualifier,
552 5
                    $rate
553 2
                );
554
            }
555 155
            $opt[] = $po;
556
        }
557
558
        return $opt;
559
    }
560
561
    /**
562 155
     * @param ExemptTax[] $exemptTaxes
563
     * @return PricingOptionGroup[]
564 155
     */
565 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...
566 155
    {
567 5
        $opt = [];
568
569 5
        if (!empty($exemptTaxes)) {
570 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_EXEMPT_FROM_TAX);
571 2
572 2
            foreach ($exemptTaxes as $tax) {
573
                $po->taxInformation[] = new TaxInformation(
574 5
                    $tax->countryCode,
575 2
                    $tax->taxNature
576
                );
577 155
            }
578
579
            $opt[] = $po;
580
        }
581
582
        return $opt;
583
    }
584
585 155
    /**
586
     * @param \DateTime|null $pastDate
587 155
     * @return PricingOptionGroup[]
588
     */
589 155 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...
590 5
    {
591
        $opt = [];
592 5
593
        if ($pastDate instanceof \DateTime) {
594 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAST_DATE_PRICING);
595 2
596
            $po->dateInformation = new DateInformation(
597 155
                DateInformation::OPT_DATE_OVERRIDE,
598
                $pastDate
599
            );
600
601
            $opt[] = $po;
602
        }
603
604 155
        return $opt;
605
    }
606 155
607
608 155
    /**
609 5
     * @param FormOfPayment[] $formOfPayment
610
     * @return PricingOptionGroup[]
611 5
     */
612
    protected static function loadFormOfPayment($formOfPayment)
613 5
    {
614 2
        $opt = [];
615
616 155
        if (!empty($formOfPayment)) {
617
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FORM_OF_PAYMENT);
618
619
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
620
621
            $opt[] = $po;
622
        }
623
624
        return $opt;
625
    }
626
627
    /**
628
     * @param PaxSegRef[] $references
629
     * @return PricingOptionGroup[]
630
     */
631
    protected static function loadReferences($references)
632
    {
633
        $opt = [];
634
635
        if (!empty($references)) {
636
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAX_SEGMENT_TST_SELECTION);
637
638
            $po->paxSegTstReference = new PaxSegTstReference($references);
639
640
            $opt[] = $po;
641
        }
642
643
        return $opt;
644
    }
645
646
    /**
647
     * Load ZAP-Off
648
     *
649
     * @param ZapOff[] $zapOffs
650
     * @return PricingOptionGroup[]
651
     */
652
    protected static function loadZapOffs($zapOffs)
653
    {
654
        $opt = [];
655
        if (!empty($zapOffs)) {
656 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...
657
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_ZAP_OFF);
658
659
                $po->penDisInformation = new PenDisInformation(
660
                    PenDisInformation::QUAL_ZAPOFF_DISCOUNT,
661
                    [$zapOff]
662
                );
663
664
                if (!empty($zapOff->paxSegRefs)) {
665
                    $po->paxSegTstReference = new PaxSegTstReference($zapOff->paxSegRefs);
666
                }
667
668
                $opt[] = $po;
669
            }
670
        }
671
672
        return $opt;
673
    }
674
675
    /**
676
     * Load Cabins
677
     *
678
     * @param Cabin[] $cabins
679
     * @return array
680
     */
681
    protected static function loadCabins($cabins)
682
    {
683
        $opt = [];
684
        if (!empty($cabins)) {
685
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CABIN);
686
            $criteriaDetails = [];
687
            foreach ($cabins as $cabin) {
688
                $criteriaDetails[] = new CriteriaDetails($cabin->cabinType, $cabin->cabinCode);
689
            }
690
            $po->optionDetail = new OptionDetail($criteriaDetails);
691
            $opt[] = $po;
692
        }
693
694
        return $opt;
695
    }
696
}
697