Passed
Pull Request — master (#217)
by
unknown
10:59
created

loadPricingOptionsFromRequestOptions()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 100

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 77
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 100
c 0
b 0
f 0
ccs 77
cts 77
cp 1
rs 8
cc 2
nc 2
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\FormOfPayment;
30
use Amadeus\Client\RequestOptions\Fare\PricePnr\ObFee;
31
use Amadeus\Client\RequestOptions\Fare\PricePnr\PaxSegRef;
32
use Amadeus\Client\RequestOptions\Fare\PricePnr\Tax;
33
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
34
use Amadeus\Client\RequestOptions\FarePricePnrWithLowerFaresOptions as LowerFareOpt;
35
use Amadeus\Client\RequestOptions\FarePricePnrWithLowestFareOptions as LowestFareOpt;
36
use Amadeus\Client\RequestOptions\Fare\InformativePricing\PricingOptions as InformativePriceOpt;
37
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
38
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
39
use Amadeus\Client\Struct\Fare\PricePnr13\DateInformation;
40
use Amadeus\Client\Struct\Fare\PricePnr13\FormOfPaymentInformation;
41
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentFlyerInformation;
42
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentTravellerDetails;
43
use Amadeus\Client\Struct\Fare\PricePnr13\LocationInformation;
44
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
45
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
46
use Amadeus\Client\Struct\Fare\PricePnr13\PenDisInformation;
47
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
48
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionKey;
49
use Amadeus\Client\Struct\Fare\PricePnr13\TaxData;
50
use Amadeus\Client\Struct\Fare\PricePnr13\TaxInformation;
51
52
/**
53
 * Fare_PricePNRWithBookingClass v 13 and higher structure
54
 *
55
 * @package Amadeus\Client\Struct\Fare
56
 * @author dieter <[email protected]>
57
 */
58
class PricePNRWithBookingClass13 extends BasePricingMessage
59
{
60
    /**
61
     * @var PricePnr13\PricingOptionGroup[]
62
     */
63
    public $pricingOptionGroup = [];
64
65
    /**
66
     * PricePNRWithBookingClass13 constructor.
67
     *
68
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt|InformativePriceOpt|null $options
69
     * @throws MessageVersionUnsupportedException
70
     */
71 88
    public function __construct($options)
72
    {
73 88
        if (!is_null($options)) {
74 88
            $this->pricingOptionGroup = $this->loadPricingOptionsFromRequestOptions($options);
75 44
        }
76 88
    }
77
78
    /**
79
     * Load an array of PricingOptionGroup objects from the Pricing request options.
80
     *
81
     * Extracted because this method is also used in the InformativePricingWithoutPnr messages.
82
     *
83
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt|InformativePriceOpt $options
84
     * @return PricingOptionGroup[]
85
     */
86 116
    public static function loadPricingOptionsFromRequestOptions($options)
87
    {
88 116
        $priceOptions = [];
89
90 116
        $priceOptions = self::mergeOptions(
91 116
            $priceOptions,
92 116
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
93 58
        );
94
95 116
        $priceOptions = self::mergeOptions(
96 116
            $priceOptions,
97 116
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
98 58
        );
99
100 116
        $priceOptions = self::mergeOptions(
101 116
            $priceOptions,
102 116
            self::makePricingOptionFareBasisOverride($options->pricingsFareBasis)
103 58
        );
104
105 116
        $priceOptions = self::mergeOptions(
106 116
            $priceOptions,
107 116
            self::loadCorpNegoFare($options->corporateNegoFare)
108 58
        );
109
110 116
        $priceOptions = self::mergeOptions(
111 116
            $priceOptions,
112 116
            self::loadCorpUniFares($options->corporateUniFares, $options->awardPricing)
113 58
        );
114
115 116
        $priceOptions = self::mergeOptions(
116 116
            $priceOptions,
117 116
            self::loadObFees($options->obFees, $options->obFeeRefs)
118 58
        );
119
120 116
        $priceOptions = self::mergeOptions(
121 116
            $priceOptions,
122 116
            self::loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs)
123 58
        );
124
125 116
        $priceOptions = self::mergeOptions(
126 116
            $priceOptions,
127 116
            self::loadPointOverrides(
128 116
                $options->pointOfSaleOverride,
129 116
                $options->pointOfTicketingOverride
130 58
            )
131 58
        );
132
133 116
        $priceOptions = self::mergeOptions(
134 116
            $priceOptions,
135 116
            self::loadPricingLogic($options->pricingLogic)
136 58
        );
137
138 116
        $priceOptions = self::mergeOptions(
139 116
            $priceOptions,
140 116
            self::loadTicketType($options->ticketType)
141 58
        );
142
143 116
        $priceOptions = self::mergeOptions(
144 116
            $priceOptions,
145 116
            self::loadTaxes($options->taxes)
146 58
        );
147
148 116
        $priceOptions = self::mergeOptions(
149 116
            $priceOptions,
150 116
            self::loadExemptTaxes($options->exemptTaxes)
151 58
        );
152
153 116
        $priceOptions = self::mergeOptions(
154 116
            $priceOptions,
155 116
            self::loadPastDate($options->pastDatePricing)
156 58
        );
157
158
159 116
        $priceOptions = self::mergeOptions(
160 116
            $priceOptions,
161 116
            self::loadFormOfPayment($options->formOfPayment)
162 58
        );
163
164 116
        $priceOptions = self::mergeOptions(
165 116
            $priceOptions,
166 116
            self::loadReferences($options->references)
167 58
        );
168
169 116
        $priceOptions = self::mergeOptions(
170 116
            $priceOptions,
171 116
            self::makeOverrideOptions($options->overrideOptions, $priceOptions)
172 58
        );
173
174 116
        $priceOptions = self::mergeOptions(
175 116
            $priceOptions,
176 116
            self::makeOverrideOptionsWithCriteria($options->overrideOptionsWithCriteria, $priceOptions)
177 58
        );
178
179
        // All options processed, no options found:
180 116
        if (empty($priceOptions)) {
181 24
            $priceOptions[] = new PricingOptionGroup(PricingOptionKey::OPTION_NO_OPTION);
182 12
        }
183
184 116
        return $priceOptions;
185
    }
186
187
    /**
188
     * @param string[] $overrideOptions
189
     * @param PricingOptionGroup[] $priceOptions
190
     * @return PricingOptionGroup[]
191
     */
192 116 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...
193
    {
194 116
        $opt = [];
195
196 116
        foreach ($overrideOptions as $overrideOption) {
197 32
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
198 32
                $opt[] = new PricingOptionGroup($overrideOption);
199 16
            }
200 58
        }
201
202 116
        return $opt;
203
    }
204
205
    /**
206
     * @param string[] $overrideOptionsWithCriteria
207
     * @param PricingOptionGroup[] $priceOptions
208
     * @return PricingOptionGroup[]
209
     */
210 116
    protected static function makeOverrideOptionsWithCriteria($overrideOptionsWithCriteria, $priceOptions)
211
    {
212 116
        $opt = [];
213
214 116
        foreach ($overrideOptionsWithCriteria as $overrideOptionWithCriteria) {
215
            if (!self::hasPricingGroup($overrideOptionWithCriteria["key"], $priceOptions)) {
216
                $opt[] = new PricingOptionGroup($overrideOptionWithCriteria["key"], $overrideOptionWithCriteria["optionDetail"]);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
217
            }
218 58
        }
219
220 116
        return $opt;
221
    }
222
223
    /**
224
     * @param string|null $validatingCarrier
225
     * @return PricePnr13\PricingOptionGroup[]
226
     */
227 116 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...
228
    {
229 116
        $opt = [];
230
231 116
        if ($validatingCarrier !== null) {
232 28
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);
233
234 28
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
235
236 28
            $opt[] = $po;
237 14
        }
238
239 116
        return $opt;
240
    }
241
242
    /**
243
     * @param string|null $currency
244
     * @return PricePnr13\PricingOptionGroup[]
245
     */
246 116 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...
247
    {
248 116
        $opt = [];
249
250 116
        if ($currency !== null) {
251 28
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
252
253 28
            $po->currency = new Currency($currency);
254
255 28
            $opt[] = $po;
256 14
        }
257
258 116
        return $opt;
259
    }
260
261
    /**
262
     * @param FareBasis[] $pricingsFareBasis
263
     * @return PricePnr13\PricingOptionGroup[]
264
     */
265 116 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...
266
    {
267 116
        $opt = [];
268
269 116
        if ($pricingsFareBasis !== null) {
270 116
            foreach ($pricingsFareBasis as $pricingFareBasis) {
271 16
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
272
273
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
274 16
                $po->optionDetail = new OptionDetail(
275 16
                    $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...
276 8
                );
277
278
                //Support for legacy segmentReference to be removed when breaking BC:
279 16
                $po->paxSegTstReference = new PaxSegTstReference(
280 16
                    $pricingFareBasis->references,
281 16
                    $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...
282 8
                );
283
284 16
                $opt[] = $po;
285 58
            }
286 58
        }
287
288 116
        return $opt;
289
    }
290
291
    /**
292
     * Load corporate negofare
293
     *
294
     * @param string|null $corporateNegoFare
295
     * @return PricingOptionGroup[]
296
     */
297 116
    protected static function loadCorpNegoFare($corporateNegoFare)
298
    {
299 116
        $opt = [];
300
301 116
        if ($corporateNegoFare !== null) {
302 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_NEGOTIATED_FARES);
303
304 4
            $po->optionDetail = new OptionDetail($corporateNegoFare);
305
306 4
            $opt[] = $po;
307 2
        }
308
309 116
        return $opt;
310
    }
311
312
    /**
313
     * Load corporate unifares
314
     *
315
     * @param string[] $corporateUniFares
316
     * @param AwardPricing|null $awardPricing
317
     * @return PricingOptionGroup[]
318
     */
319 116
    protected static function loadCorpUniFares($corporateUniFares, $awardPricing)
320
    {
321 116
        $opt = [];
322
323 116
        if (!empty($corporateUniFares)) {
324 8
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
325 8
            $po->optionDetail = new OptionDetail($corporateUniFares);
326 8
            $opt[] = $po;
327
328 8
            if (!empty($awardPricing)) {
329 4
                $opt[] = self::loadAwardPricing($awardPricing);
330 2
            }
331 4
        }
332
333 116
        return $opt;
334
    }
335
336
    /**
337
     * @param AwardPricing $awardPricing
338
     * @return PricingOptionGroup
339
     */
340 4 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...
341
    {
342 4
        $po = new PricingOptionGroup(PricingOptionKey::OPTION_AWARD_PRICING);
343
344 4
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
345
346 4
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
347 4
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
348 4
            $awardPricing->tierLevel
349 2
        );
350
351 4
        return $po;
352
    }
353
354
    /**
355
     * Load OB Fees
356
     *
357
     * @param ObFee[] $obFees
358
     * @param PaxSegRef[] $obFeeRefs
359
     * @return PricingOptionGroup[]
360
     */
361 116 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...
362
    {
363 116
        $opt = [];
364
365 116
        if (!empty($obFees)) {
366 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_OB_FEES);
367
368 4
            $po->penDisInformation = new PenDisInformation(
369 4
                PenDisInformation::QUAL_OB_FEES,
370 2
                $obFees
371 2
            );
372
373 4
            if (!empty($obFeeRefs)) {
374 4
                $po->paxSegTstReference = new PaxSegTstReference($obFeeRefs);
375 2
            }
376
377 4
            $opt[] = $po;
378 2
        }
379
380 116
        return $opt;
381
    }
382
383
    /**
384
     * @param string[] $paxDiscount
385
     * @param PaxSegRef[] $paxDiscountCodeRefs
386
     * @return PricingOptionGroup[]
387
     */
388 116 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...
389
    {
390 116
        $opt = [];
391
392 116
        if (!empty($paxDiscount)) {
393 16
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
394
395 16
            $po->penDisInformation = new PenDisInformation(
396 16
                PenDisInformation::QUAL_DISCOUNT,
397 8
                $paxDiscount
398 8
            );
399
400 16
            if (!empty($paxDiscountCodeRefs)) {
401 16
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
402 8
            }
403
404 16
            $opt[] = $po;
405 8
        }
406
407 116
        return $opt;
408
    }
409
410
    /**
411
     * @param string|null $posOverride
412
     * @param string|null $potOverride
413
     * @return PricingOptionGroup[]
414
     */
415 116 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...
416
    {
417 116
        $opt = [];
418
419 116
        if (!empty($posOverride)) {
420 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
421
422 4
            $po->locationInformation = new LocationInformation(
423 4
                LocationInformation::TYPE_POINT_OF_SALE,
424 2
                $posOverride
425 2
            );
426
427 4
            $opt[] = $po;
428 2
        }
429
430 116
        if (!empty($potOverride)) {
431 4
            $po2 = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
432
433 4
            $po2->locationInformation = new LocationInformation(
434 4
                LocationInformation::TYPE_POINT_OF_TICKETING,
435 2
                $potOverride
436 2
            );
437
438 4
            $opt[] = $po2;
439 2
        }
440
441 116
        return $opt;
442
    }
443
444
    /**
445
     * @param string|null $pricingLogic
446
     * @return PricingOptionGroup[]
447
     */
448 116 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...
449
    {
450 116
        $opt = [];
451
452 116
        if (!empty($pricingLogic)) {
453 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PRICING_LOGIC);
454 4
            $po->optionDetail = new OptionDetail($pricingLogic);
455 4
            $opt[] = $po;
456 2
        }
457
458 116
        return $opt;
459
    }
460
461
    /**
462
     * @param string|null $ticketType
463
     * @return PricingOptionGroup[]
464
     */
465 116 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...
466
    {
467 116
        $opt = [];
468
469 116
        if (!empty($ticketType)) {
470 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_TICKET_TYPE);
471
472 4
            $po->optionDetail = new OptionDetail($ticketType);
473
474 4
            $opt[] = $po;
475 2
        }
476
477 116
        return $opt;
478
    }
479
480
    /**
481
     * @param Tax[] $taxes
482
     * @return PricingOptionGroup[]
483
     */
484 116 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...
485
    {
486 116
        $opt = [];
487
488 116
        if (!empty($taxes)) {
489 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_ADD_TAX);
490
491 4
            foreach ($taxes as $tax) {
492 4
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
493 4
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
494
495 4
                $po->taxInformation[] = new TaxInformation(
496 4
                    $tax->countryCode,
497 4
                    $tax->taxNature,
498 4
                    $qualifier,
499 2
                    $rate
500 2
                );
501 2
            }
502 4
            $opt[] = $po;
503 2
        }
504
505 116
        return $opt;
506
    }
507
508
    /**
509
     * @param ExemptTax[] $exemptTaxes
510
     * @return PricingOptionGroup[]
511
     */
512 116 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...
513
    {
514 116
        $opt = [];
515
516 116
        if (!empty($exemptTaxes)) {
517 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_EXEMPT_FROM_TAX);
518
519 4
            foreach ($exemptTaxes as $tax) {
520 4
                $po->taxInformation[] = new TaxInformation(
521 4
                    $tax->countryCode,
522 4
                    $tax->taxNature
523 2
                );
524 2
            }
525
526 4
            $opt[] = $po;
527 2
        }
528
529 116
        return $opt;
530
    }
531
532
    /**
533
     * @param \DateTime|null $pastDate
534
     * @return PricingOptionGroup[]
535
     */
536 116 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...
537
    {
538 116
        $opt = [];
539
540 116
        if ($pastDate instanceof \DateTime) {
541 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAST_DATE_PRICING);
542
543 4
            $po->dateInformation = new DateInformation(
544 4
                DateInformation::OPT_DATE_OVERRIDE,
545 2
                $pastDate
546 2
            );
547
548 4
            $opt[] = $po;
549 2
        }
550
551 116
        return $opt;
552
    }
553
554
555
    /**
556
     * @param FormOfPayment[] $formOfPayment
557
     * @return PricingOptionGroup[]
558
     */
559 116
    protected static function loadFormOfPayment($formOfPayment)
560
    {
561 116
        $opt = [];
562
563 116
        if (!empty($formOfPayment)) {
564 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FORM_OF_PAYMENT);
565
566 4
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
567
568 4
            $opt[] = $po;
569 2
        }
570
571 116
        return $opt;
572
    }
573
574
    /**
575
     * @param PaxSegRef[] $references
576
     * @return PricingOptionGroup[]
577
     */
578 116
    protected static function loadReferences($references)
579
    {
580 116
        $opt = [];
581
582 116
        if (!empty($references)) {
583 4
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAX_SEGMENT_TST_SELECTION);
584
585 4
            $po->paxSegTstReference = new PaxSegTstReference($references);
586
587 4
            $opt[] = $po;
588 2
        }
589
590 116
        return $opt;
591
    }
592
}
593