Passed
Pull Request — master (#344)
by Andrew
04:35
created

makePricingOptionForCurrencyOverride()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 14
loc 14
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.7998
cc 2
nc 2
nop 1
crap 2
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 120
     * @throws MessageVersionUnsupportedException
72
     */
73 120
    public function __construct($options)
74 120
    {
75 48
        if (!is_null($options)) {
76 120
            $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 155
     * @return PricingOptionGroup[]
87
     */
88 155
    public static function loadPricingOptionsFromRequestOptions($options)
89
    {
90 155
        $priceOptions = [];
91 155
92 155
        $priceOptions = self::mergeOptions(
93 62
            $priceOptions,
94
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
95 155
        );
96 155
97 155
        $priceOptions = self::mergeOptions(
98 62
            $priceOptions,
99
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
100 155
        );
101 155
102 155
        $priceOptions = self::mergeOptions(
103 62
            $priceOptions,
104
            self::makePricingOptionFareBasisOverride($options->pricingsFareBasis)
105 155
        );
106 155
107 155
        $priceOptions = self::mergeOptions(
108 62
            $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 155
        );
111 155
112 155
        $priceOptions = self::mergeOptions(
113 62
            $priceOptions,
114
            self::loadCorpNegoFare($options->corporateNegoFare)
115 155
        );
116 155
117 155
        $priceOptions = self::mergeOptions(
118 62
            $priceOptions,
119
            self::loadCorpUniFares($options->corporateUniFares, $options->awardPricing)
120 155
        );
121 155
122 155
        $priceOptions = self::mergeOptions(
123 62
            $priceOptions,
124
            self::loadObFees($options->obFees, $options->obFeeRefs)
125 155
        );
126 155
127 155
        $priceOptions = self::mergeOptions(
128 62
            $priceOptions,
129
            self::loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs)
130 155
        );
131 155
132 155
        $priceOptions = self::mergeOptions(
133 155
            $priceOptions,
134 155
            self::loadPointOverrides(
135 62
                $options->pointOfSaleOverride,
136 62
                $options->pointOfTicketingOverride
137
            )
138 155
        );
139 155
140 155
        $priceOptions = self::mergeOptions(
141 62
            $priceOptions,
142
            self::loadPricingLogic($options->pricingLogic)
143 155
        );
144 155
145 155
        $priceOptions = self::mergeOptions(
146 62
            $priceOptions,
147
            self::loadTicketType($options->ticketType)
148 155
        );
149 155
150 155
        $priceOptions = self::mergeOptions(
151 62
            $priceOptions,
152
            self::loadTaxes($options->taxes)
153 155
        );
154 155
155 155
        $priceOptions = self::mergeOptions(
156 62
            $priceOptions,
157
            self::loadExemptTaxes($options->exemptTaxes)
158 155
        );
159 155
160 155
        $priceOptions = self::mergeOptions(
161 62
            $priceOptions,
162
            self::loadPastDate($options->pastDatePricing)
163
        );
164 155
165 155
166 155
        $priceOptions = self::mergeOptions(
167 62
            $priceOptions,
168
            self::loadFormOfPayment($options->formOfPayment)
169 155
        );
170 155
171 155
        $priceOptions = self::mergeOptions(
172 62
            $priceOptions,
173
            self::loadReferences($options->references)
174 155
        );
175 155
176 155
        $priceOptions = self::mergeOptions(
177 62
            $priceOptions,
178
            self::makeOverrideOptions($options->overrideOptions, $priceOptions)
179 155
        );
180 155
181 155
        $priceOptions = self::mergeOptions(
182 62
            $priceOptions,
183
            self::makeOverrideOptionsWithCriteria($options->overrideOptionsWithCriteria, $priceOptions)
184
        );
185 155
186 30
        $priceOptions = self::mergeOptions(
187 12
            $priceOptions,
188
            self::loadZapOffs($options->zapOff)
189 155
        );
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 155
    }
198
199 155
    /**
200
     * @param string[] $overrideOptions
201 155
     * @param PricingOptionGroup[] $priceOptions
202 40
     * @return PricingOptionGroup[]
203 40
     */
204 16 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 62
    {
206
        $opt = [];
207 155
208
        foreach ($overrideOptions as $overrideOption) {
209
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
210
                $opt[] = new PricingOptionGroup($overrideOption);
211
            }
212
        }
213
214
        return $opt;
215 155
    }
216
217 155
    /**
218
     * @param string[] $overrideOptionsWithCriteria
219 155
     * @param PricingOptionGroup[] $priceOptions
220 5
     * @return PricingOptionGroup[]
221 5
     */
222 2
    protected static function makeOverrideOptionsWithCriteria($overrideOptionsWithCriteria, $priceOptions)
223 62
    {
224
        $opt = [];
225 155
226
        foreach ($overrideOptionsWithCriteria as $overrideOptionWithCriteria) {
227
            if (!self::hasPricingGroup($overrideOptionWithCriteria["key"], $priceOptions)) {
228
                $opt[] = new PricingOptionGroup($overrideOptionWithCriteria["key"], $overrideOptionWithCriteria["optionDetail"]);
229
            }
230
        }
231
232 155
        return $opt;
233
    }
234 155
235
    /**
236 155
     * @param string|null $validatingCarrier
237 40
     * @return PricePnr13\PricingOptionGroup[]
238
     */
239 40 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 40
        $opt = [];
242 16
243
        if ($validatingCarrier !== null) {
244 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);
245
246
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
247
248
            $opt[] = $po;
249
        }
250
251 155
        return $opt;
252
    }
253 155
254
    /**
255 155
     * @param string|null $currency
256 40
     * @return PricePnr13\PricingOptionGroup[]
257
     */
258 40 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 40
        $opt = [];
261 16
262
        if ($currency !== null) {
263 155
            $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 155
    }
272
273 155
274
    /**
275 155
     * @param FareBasis[] $pricingsFareBasis
276 155
     * @return PricePnr13\PricingOptionGroup[]
277 20
     */
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 20
        $opt = [];
281 20
282 8
        if ($pricingsFareBasis !== null) {
283
            foreach ($pricingsFareBasis as $pricingFareBasis) {
284
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
285 20
286 20
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
287 20
                $po->optionDetail = new OptionDetail(
288 8
                    $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 20
291 62
                //Support for legacy segmentReference to be removed when breaking BC:
292 62
                $po->paxSegTstReference = new PaxSegTstReference(
293
                    $pricingFareBasis->references,
294 155
                    $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 155
304
    /**
305 155
     * Load fare-family pricing option and return it.
306
     *
307 155
     * @param string $fareFamily input fare-family, e.g. "CLASSIC"
308 5
     * @return PricePnr13\PricingOptionGroup[]
309 5
     */
310
    protected static function makePricingOptionFareFamilyOverride($fareFamily)
311 5
    {
312 2
        $opt = [];
313
314 155
        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
321
                    $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
322
                    $po->optionDetail = new OptionDetail([['FF' => $item->fareFamily]]);
323 155
                    $po->paxSegTstReference =  new PaxSegTstReference($item->paxSegRefs);
324
325 155
326
                    $opt[] =$po;
327 155
                }
328 5
329
            } else {
330 5
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
331
                $po->optionDetail = new OptionDetail([['FF' => $fareFamily]]);
332 5
333 2
                $opt[] = $po;
334
            }
335 155
336
        }
337
338
        return $opt;
339
    }
340
341
    /**
342
     * Load corporate negofare
343
     *
344
     * @param string|null $corporateNegoFare
345 155
     * @return PricingOptionGroup[]
346
     */
347 155
    protected static function loadCorpNegoFare($corporateNegoFare)
348
    {
349 155
        $opt = [];
350 10
351 10
        if ($corporateNegoFare !== null) {
352 10
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_NEGOTIATED_FARES);
353
354 10
            $po->optionDetail = new OptionDetail($corporateNegoFare);
355 5
356 2
            $opt[] = $po;
357 4
        }
358
359 155
        return $opt;
360
    }
361
362
    /**
363
     * Load corporate unifares
364
     *
365
     * @param string[] $corporateUniFares
366 5
     * @param AwardPricing|null $awardPricing
367
     * @return PricingOptionGroup[]
368 5
     */
369
    protected static function loadCorpUniFares($corporateUniFares, $awardPricing)
370 5
    {
371
        $opt = [];
372 5
373 5
        if (!empty($corporateUniFares)) {
374 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
375 2
            $po->optionDetail = new OptionDetail($corporateUniFares);
376
            $opt[] = $po;
377 5
378
            if (!empty($awardPricing)) {
379
                $opt[] = self::loadAwardPricing($awardPricing);
380
            }
381
        }
382
383
        return $opt;
384
    }
385
386
    /**
387 155
     * @param AwardPricing $awardPricing
388
     * @return PricingOptionGroup
389 155
     */
390 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...
391 155
    {
392 5
        $po = new PricingOptionGroup(PricingOptionKey::OPTION_AWARD_PRICING);
393
394 5
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
395 5
396 2
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
397 2
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
398
            $awardPricing->tierLevel
399 5
        );
400 5
401 2
        return $po;
402
    }
403 5
404 2
    /**
405
     * Load OB Fees
406 155
     *
407
     * @param ObFee[] $obFees
408
     * @param PaxSegRef[] $obFeeRefs
409
     * @return PricingOptionGroup[]
410
     */
411 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...
412
    {
413
        $opt = [];
414 155
415
        if (!empty($obFees)) {
416 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_OB_FEES);
417
418 155
            $po->penDisInformation = new PenDisInformation(
419 20
                PenDisInformation::QUAL_OB_FEES,
420
                $obFees
421 20
            );
422 20
423 8
            if (!empty($obFeeRefs)) {
424 8
                $po->paxSegTstReference = new PaxSegTstReference($obFeeRefs);
425
            }
426 20
427 20
            $opt[] = $po;
428 8
        }
429
430 20
        return $opt;
431 8
    }
432
433 155
    /**
434
     * @param string[] $paxDiscount
435
     * @param PaxSegRef[] $paxDiscountCodeRefs
436
     * @return PricingOptionGroup[]
437
     */
438 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...
439
    {
440
        $opt = [];
441 155
442
        if (!empty($paxDiscount)) {
443 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
444
445 155
            $po->penDisInformation = new PenDisInformation(
446 5
                PenDisInformation::QUAL_DISCOUNT,
447
                $paxDiscount
448 5
            );
449 5
450 2
            if (!empty($paxDiscountCodeRefs)) {
451 2
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
452
            }
453 5
454 2
            $opt[] = $po;
455
        }
456 155
457 5
        return $opt;
458
    }
459 5
460 5
    /**
461 2
     * @param string|null $posOverride
462 2
     * @param string|null $potOverride
463
     * @return PricingOptionGroup[]
464 5
     */
465 2 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...
466
    {
467 155
        $opt = [];
468
469
        if (!empty($posOverride)) {
470
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
471
472
            $po->locationInformation = new LocationInformation(
473
                LocationInformation::TYPE_POINT_OF_SALE,
474 155
                $posOverride
475
            );
476 155
477
            $opt[] = $po;
478 155
        }
479 5
480 5
        if (!empty($potOverride)) {
481 5
            $po2 = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
482 2
483
            $po2->locationInformation = new LocationInformation(
484 155
                LocationInformation::TYPE_POINT_OF_TICKETING,
485
                $potOverride
486
            );
487
488
            $opt[] = $po2;
489
        }
490
491 155
        return $opt;
492
    }
493 155
494
    /**
495 155
     * @param string|null $pricingLogic
496 5
     * @return PricingOptionGroup[]
497
     */
498 5 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...
499
    {
500 5
        $opt = [];
501 2
502
        if (!empty($pricingLogic)) {
503 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PRICING_LOGIC);
504
            $po->optionDetail = new OptionDetail($pricingLogic);
505
            $opt[] = $po;
506
        }
507
508
        return $opt;
509
    }
510 155
511
    /**
512 155
     * @param string|null $ticketType
513
     * @return PricingOptionGroup[]
514 155
     */
515 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...
516
    {
517 5
        $opt = [];
518 5
519 5
        if (!empty($ticketType)) {
520
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_TICKET_TYPE);
521 5
522 5
            $po->optionDetail = new OptionDetail($ticketType);
523 5
524 4
            $opt[] = $po;
525 2
        }
526 2
527 2
        return $opt;
528 5
    }
529 2
530
    /**
531 155
     * @param Tax[] $taxes
532
     * @return PricingOptionGroup[]
533
     */
534 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...
535
    {
536
        $opt = [];
537
538 155
        if (!empty($taxes)) {
539
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_ADD_TAX);
540 155
541
            foreach ($taxes as $tax) {
542 155
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
543 5
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
544
545 5
                $po->taxInformation[] = new TaxInformation(
546 5
                    $tax->countryCode,
547 5
                    $tax->taxNature,
548 5
                    $qualifier,
549 2
                    $rate
550 2
                );
551
            }
552 5
            $opt[] = $po;
553 2
        }
554
555 155
        return $opt;
556
    }
557
558
    /**
559
     * @param ExemptTax[] $exemptTaxes
560
     * @return PricingOptionGroup[]
561
     */
562 155 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...
563
    {
564 155
        $opt = [];
565
566 155
        if (!empty($exemptTaxes)) {
567 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_EXEMPT_FROM_TAX);
568
569 5
            foreach ($exemptTaxes as $tax) {
570 5
                $po->taxInformation[] = new TaxInformation(
571 2
                    $tax->countryCode,
572 2
                    $tax->taxNature
573
                );
574 5
            }
575 2
576
            $opt[] = $po;
577 155
        }
578
579
        return $opt;
580
    }
581
582
    /**
583
     * @param \DateTime|null $pastDate
584
     * @return PricingOptionGroup[]
585 155
     */
586 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...
587 155
    {
588
        $opt = [];
589 155
590 5
        if ($pastDate instanceof \DateTime) {
591
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAST_DATE_PRICING);
592 5
593
            $po->dateInformation = new DateInformation(
594 5
                DateInformation::OPT_DATE_OVERRIDE,
595 2
                $pastDate
596
            );
597 155
598
            $opt[] = $po;
599
        }
600
601
        return $opt;
602
    }
603
604 155
605
    /**
606 155
     * @param FormOfPayment[] $formOfPayment
607
     * @return PricingOptionGroup[]
608 155
     */
609 5
    protected static function loadFormOfPayment($formOfPayment)
610
    {
611 5
        $opt = [];
612
613 5
        if (!empty($formOfPayment)) {
614 2
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FORM_OF_PAYMENT);
615
616 155
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
617
618
            $opt[] = $po;
619
        }
620
621
        return $opt;
622
    }
623
624
    /**
625
     * @param PaxSegRef[] $references
626
     * @return PricingOptionGroup[]
627
     */
628
    protected static function loadReferences($references)
629
    {
630
        $opt = [];
631
632
        if (!empty($references)) {
633
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAX_SEGMENT_TST_SELECTION);
634
635
            $po->paxSegTstReference = new PaxSegTstReference($references);
636
637
            $opt[] = $po;
638
        }
639
640
        return $opt;
641
    }
642
643
    /**
644
     * Load ZAP-Off
645
     *
646
     * @param ZapOff[] $zapOffs
647
     * @return PricingOptionGroup[]
648
     */
649
    protected static function loadZapOffs($zapOffs)
650
    {
651
        $opt = [];
652
        if (!empty($zapOffs)) {
653 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...
654
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_ZAP_OFF);
655
656
                $po->penDisInformation = new PenDisInformation(
657
                    PenDisInformation::QUAL_ZAPOFF_DISCOUNT,
658
                    [$zapOff]
659
                );
660
661
                if (!empty($zapOff->paxSegRefs)) {
662
                    $po->paxSegTstReference = new PaxSegTstReference($zapOff->paxSegRefs);
663
                }
664
665
                $opt[] = $po;
666
            }
667
        }
668
669
        return $opt;
670
    }
671
}
672