Completed
Pull Request — master (#344)
by Andrew
04:32
created

PricePNRWithBookingClass13   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 610
Duplicated Lines 41.97 %

Coupling/Cohesion

Components 1
Dependencies 19

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 58
lcom 1
cbo 19
dl 256
loc 610
ccs 289
cts 289
cp 1
rs 4.55
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
B loadPricingOptionsFromRequestOptions() 0 110 2
A makeOverrideOptions() 12 12 3
A makeOverrideOptionsWithCriteria() 0 12 3
A makePricingOptionForValidatingCarrier() 14 14 2
A makePricingOptionForCurrencyOverride() 14 14 2
A makePricingOptionFareBasisOverride() 25 25 3
A makePricingOptionFareFamilyOverride() 9 28 4
A loadCorpNegoFare() 0 14 2
A loadCorpUniFares() 0 16 3
A loadAwardPricing() 13 13 1
A loadObFees() 21 21 3
A loadPaxDiscount() 21 21 3
A loadPointOverrides() 28 28 3
A loadPricingLogic() 12 12 2
A loadTicketType() 14 14 2
A loadTaxes() 23 23 5
A loadExemptTaxes() 19 19 3
A loadPastDate() 17 17 2
A loadFormOfPayment() 0 14 2
A loadReferences() 0 14 2
A loadZapOffs() 14 22 4

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like PricePNRWithBookingClass13 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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

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

1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Fare;
24
25
use Amadeus\Client\RequestCreator\MessageVersionUnsupportedException;
26
use Amadeus\Client\RequestOptions\Fare\PricePnr\AwardPricing;
27
use Amadeus\Client\RequestOptions\Fare\PricePnr\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
                    $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
321
                    $po->optionDetail = new OptionDetail([['FF' => $item->fareFamily]]);
322
                    $po->paxSegTstReference = new PaxSegTstReference($item->paxSegRefs);
323 155
                    
324
                    $opt[] = $po;
325 155
                }
326
327 155
            } else {
328 5
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_FAMILY);
329
                $po->optionDetail = new OptionDetail([['FF' => $fareFamily]]);
330 5
331
                $opt[] = $po;
332 5
            }
333 2
334
        }
335 155
336
        return $opt;
337
    }
338
339
    /**
340
     * Load corporate negofare
341
     *
342
     * @param string|null $corporateNegoFare
343
     * @return PricingOptionGroup[]
344
     */
345 155
    protected static function loadCorpNegoFare($corporateNegoFare)
346
    {
347 155
        $opt = [];
348
349 155
        if ($corporateNegoFare !== null) {
350 10
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_NEGOTIATED_FARES);
351 10
352 10
            $po->optionDetail = new OptionDetail($corporateNegoFare);
353
354 10
            $opt[] = $po;
355 5
        }
356 2
357 4
        return $opt;
358
    }
359 155
360
    /**
361
     * Load corporate unifares
362
     *
363
     * @param string[] $corporateUniFares
364
     * @param AwardPricing|null $awardPricing
365
     * @return PricingOptionGroup[]
366 5
     */
367
    protected static function loadCorpUniFares($corporateUniFares, $awardPricing)
368 5
    {
369
        $opt = [];
370 5
371
        if (!empty($corporateUniFares)) {
372 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
373 5
            $po->optionDetail = new OptionDetail($corporateUniFares);
374 5
            $opt[] = $po;
375 2
376
            if (!empty($awardPricing)) {
377 5
                $opt[] = self::loadAwardPricing($awardPricing);
378
            }
379
        }
380
381
        return $opt;
382
    }
383
384
    /**
385
     * @param AwardPricing $awardPricing
386
     * @return PricingOptionGroup
387 155
     */
388 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...
389 155
    {
390
        $po = new PricingOptionGroup(PricingOptionKey::OPTION_AWARD_PRICING);
391 155
392 5
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
393
394 5
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
395 5
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
396 2
            $awardPricing->tierLevel
397 2
        );
398
399 5
        return $po;
400 5
    }
401 2
402
    /**
403 5
     * Load OB Fees
404 2
     *
405
     * @param ObFee[] $obFees
406 155
     * @param PaxSegRef[] $obFeeRefs
407
     * @return PricingOptionGroup[]
408
     */
409 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...
410
    {
411
        $opt = [];
412
413
        if (!empty($obFees)) {
414 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_OB_FEES);
415
416 155
            $po->penDisInformation = new PenDisInformation(
417
                PenDisInformation::QUAL_OB_FEES,
418 155
                $obFees
419 20
            );
420
421 20
            if (!empty($obFeeRefs)) {
422 20
                $po->paxSegTstReference = new PaxSegTstReference($obFeeRefs);
423 8
            }
424 8
425
            $opt[] = $po;
426 20
        }
427 20
428 8
        return $opt;
429
    }
430 20
431 8
    /**
432
     * @param string[] $paxDiscount
433 155
     * @param PaxSegRef[] $paxDiscountCodeRefs
434
     * @return PricingOptionGroup[]
435
     */
436 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...
437
    {
438
        $opt = [];
439
440
        if (!empty($paxDiscount)) {
441 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
442
443 155
            $po->penDisInformation = new PenDisInformation(
444
                PenDisInformation::QUAL_DISCOUNT,
445 155
                $paxDiscount
446 5
            );
447
448 5
            if (!empty($paxDiscountCodeRefs)) {
449 5
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
450 2
            }
451 2
452
            $opt[] = $po;
453 5
        }
454 2
455
        return $opt;
456 155
    }
457 5
458
    /**
459 5
     * @param string|null $posOverride
460 5
     * @param string|null $potOverride
461 2
     * @return PricingOptionGroup[]
462 2
     */
463 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...
464 5
    {
465 2
        $opt = [];
466
467 155
        if (!empty($posOverride)) {
468
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
469
470
            $po->locationInformation = new LocationInformation(
471
                LocationInformation::TYPE_POINT_OF_SALE,
472
                $posOverride
473
            );
474 155
475
            $opt[] = $po;
476 155
        }
477
478 155
        if (!empty($potOverride)) {
479 5
            $po2 = new PricingOptionGroup(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
480 5
481 5
            $po2->locationInformation = new LocationInformation(
482 2
                LocationInformation::TYPE_POINT_OF_TICKETING,
483
                $potOverride
484 155
            );
485
486
            $opt[] = $po2;
487
        }
488
489
        return $opt;
490
    }
491 155
492
    /**
493 155
     * @param string|null $pricingLogic
494
     * @return PricingOptionGroup[]
495 155
     */
496 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...
497
    {
498 5
        $opt = [];
499
500 5
        if (!empty($pricingLogic)) {
501 2
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PRICING_LOGIC);
502
            $po->optionDetail = new OptionDetail($pricingLogic);
503 155
            $opt[] = $po;
504
        }
505
506
        return $opt;
507
    }
508
509
    /**
510 155
     * @param string|null $ticketType
511
     * @return PricingOptionGroup[]
512 155
     */
513 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...
514 155
    {
515 5
        $opt = [];
516
517 5
        if (!empty($ticketType)) {
518 5
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_TICKET_TYPE);
519 5
520
            $po->optionDetail = new OptionDetail($ticketType);
521 5
522 5
            $opt[] = $po;
523 5
        }
524 4
525 2
        return $opt;
526 2
    }
527 2
528 5
    /**
529 2
     * @param Tax[] $taxes
530
     * @return PricingOptionGroup[]
531 155
     */
532 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...
533
    {
534
        $opt = [];
535
536
        if (!empty($taxes)) {
537
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_ADD_TAX);
538 155
539
            foreach ($taxes as $tax) {
540 155
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
541
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
542 155
543 5
                $po->taxInformation[] = new TaxInformation(
544
                    $tax->countryCode,
545 5
                    $tax->taxNature,
546 5
                    $qualifier,
547 5
                    $rate
548 5
                );
549 2
            }
550 2
            $opt[] = $po;
551
        }
552 5
553 2
        return $opt;
554
    }
555 155
556
    /**
557
     * @param ExemptTax[] $exemptTaxes
558
     * @return PricingOptionGroup[]
559
     */
560 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...
561
    {
562 155
        $opt = [];
563
564 155
        if (!empty($exemptTaxes)) {
565
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_EXEMPT_FROM_TAX);
566 155
567 5
            foreach ($exemptTaxes as $tax) {
568
                $po->taxInformation[] = new TaxInformation(
569 5
                    $tax->countryCode,
570 5
                    $tax->taxNature
571 2
                );
572 2
            }
573
574 5
            $opt[] = $po;
575 2
        }
576
577 155
        return $opt;
578
    }
579
580
    /**
581
     * @param \DateTime|null $pastDate
582
     * @return PricingOptionGroup[]
583
     */
584 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...
585 155
    {
586
        $opt = [];
587 155
588
        if ($pastDate instanceof \DateTime) {
589 155
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAST_DATE_PRICING);
590 5
591
            $po->dateInformation = new DateInformation(
592 5
                DateInformation::OPT_DATE_OVERRIDE,
593
                $pastDate
594 5
            );
595 2
596
            $opt[] = $po;
597 155
        }
598
599
        return $opt;
600
    }
601
602
603
    /**
604 155
     * @param FormOfPayment[] $formOfPayment
605
     * @return PricingOptionGroup[]
606 155
     */
607
    protected static function loadFormOfPayment($formOfPayment)
608 155
    {
609 5
        $opt = [];
610
611 5
        if (!empty($formOfPayment)) {
612
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_FORM_OF_PAYMENT);
613 5
614 2
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
615
616 155
            $opt[] = $po;
617
        }
618
619
        return $opt;
620
    }
621
622
    /**
623
     * @param PaxSegRef[] $references
624
     * @return PricingOptionGroup[]
625
     */
626
    protected static function loadReferences($references)
627
    {
628
        $opt = [];
629
630
        if (!empty($references)) {
631
            $po = new PricingOptionGroup(PricingOptionKey::OPTION_PAX_SEGMENT_TST_SELECTION);
632
633
            $po->paxSegTstReference = new PaxSegTstReference($references);
634
635
            $opt[] = $po;
636
        }
637
638
        return $opt;
639
    }
640
641
    /**
642
     * Load ZAP-Off
643
     *
644
     * @param ZapOff[] $zapOffs
645
     * @return PricingOptionGroup[]
646
     */
647
    protected static function loadZapOffs($zapOffs)
648
    {
649
        $opt = [];
650
        if (!empty($zapOffs)) {
651 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...
652
                $po = new PricingOptionGroup(PricingOptionKey::OPTION_ZAP_OFF);
653
654
                $po->penDisInformation = new PenDisInformation(
655
                    PenDisInformation::QUAL_ZAPOFF_DISCOUNT,
656
                    [$zapOff]
657
                );
658
659
                if (!empty($zapOff->paxSegRefs)) {
660
                    $po->paxSegTstReference = new PaxSegTstReference($zapOff->paxSegRefs);
661
                }
662
663
                $opt[] = $po;
664
            }
665
        }
666
667
        return $opt;
668
    }
669
}
670