RepricePnrWithBookingClass::loadExchangeInfo()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\Struct\Ticket;
24
25
use Amadeus\Client\RequestOptions\Fare\PricePnr\AwardPricing;
26
use Amadeus\Client\RequestOptions\Fare\PricePnr\ExemptTax;
27
use Amadeus\Client\RequestOptions\Fare\PricePnr\FareBasis;
28
use Amadeus\Client\RequestOptions\Fare\PricePnr\Tax;
29
use Amadeus\Client\RequestOptions\Ticket\ExchangeInfoOptions;
30
use Amadeus\Client\RequestOptions\Ticket\MultiRefOpt;
31
use Amadeus\Client\RequestOptions\Ticket\PaxSegRef;
32
use Amadeus\Client\RequestOptions\TicketRepricePnrWithBookingClassOptions;
33
use Amadeus\Client\Struct\BaseWsMessage;
34
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
35
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
36
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentFlyerInformation;
37
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentTravellerDetails;
38
use Amadeus\Client\Struct\Fare\PricePnr13\LocationInformation;
39
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
40
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
41
use Amadeus\Client\Struct\Fare\PricePnr13\PenDisInformation;
42
use Amadeus\Client\Struct\Fare\PricePnr13\TaxData;
43
use Amadeus\Client\Struct\Fare\PricePnr13\TaxInformation;
44
use Amadeus\Client\Struct\Ticket\RepricePnrWithBookingClass\ExchangeInformationGroup;
45
use Amadeus\Client\Struct\Ticket\RepricePnrWithBookingClass\PricingOption;
46
use Amadeus\Client\Struct\Ticket\RepricePnrWithBookingClass\PricingOptionKey;
47
48
/**
49
 * Ticket_RepricePNRWithBookingClass request structure
50
 *
51
 * @package Amadeus\Client\Struct\Ticket
52
 * @author Dieter Devlieghere <[email protected]>
53
 */
54
class RepricePnrWithBookingClass extends BaseWsMessage
55
{
56
    /**
57
     * @var ExchangeInformationGroup[]
58
     */
59
    public $exchangeInformationGroup = [];
60
61
    /**
62
     * @var PricingOption[]
63
     */
64
    public $pricingOption = [];
65
66
    /**
67
     * RepricePnrWithBookingClass constructor.
68
     *
69
     * @param TicketRepricePnrWithBookingClassOptions $options
70
     */
71
    public function __construct($options)
72
    {
73
        if (!is_null($options)) {
74
            $this->loadExchangeInfo($options->exchangeInfo);
75
76
            $this->pricingOption = $this->loadPricingOptionsFromRequestOptions($options);
77
        }
78
    }
79
80
    /**
81
     * @param ExchangeInfoOptions[] $exchangeInfo
82
     */
83
    protected function loadExchangeInfo($exchangeInfo)
84
    {
85
        foreach ($exchangeInfo as $info) {
86
            if ($info instanceof ExchangeInfoOptions) {
87
                $this->exchangeInformationGroup[] = new ExchangeInformationGroup($info);
88
            }
89
        }
90
    }
91
92
    /**
93
     * @param TicketRepricePnrWithBookingClassOptions $options
94
     * @return PricingOption[]
95
     */
96
    protected function loadPricingOptionsFromRequestOptions(TicketRepricePnrWithBookingClassOptions $options)
97
    {
98
        $priceOptions = [];
99
100
        $priceOptions = $this->mergeOptions(
101
            $priceOptions,
102
            $this->makePricingOptionForCarrier(
103
                $options->validatingCarrier,
104
                PricingOptionKey::OPTION_VALIDATING_CARRIER
105
            )
106
        );
107
108
        $priceOptions = $this->mergeOptions(
109
            $priceOptions,
110
            $this->makePricingOptionForCarrier(
111
                $options->controllingCarrier,
112
                PricingOptionKey::OPTION_OVERRIDE_CONTROLLING_CARRIER
113
            )
114
        );
115
116
        $priceOptions = $this->mergeOptions(
117
            $priceOptions,
118
            $this->loadCorpUniFares($options->corporateUniFares, $options->awardPricing)
119
        );
120
121
        $priceOptions = $this->mergeOptions(
122
            $priceOptions,
123
            $this->makePricingOptionFareBasisOverride($options->pricingsFareBasis)
124
        );
125
126
        $priceOptions = $this->mergeOptions(
127
            $priceOptions,
128
            $this->loadTaxes($options->taxes)
129
        );
130
131
        $priceOptions = $this->mergeOptions(
132
            $priceOptions,
133
            $this->loadExemptTaxes($options->exemptTaxes)
134
        );
135
136
        $priceOptions = $this->mergeOptions(
137
            $priceOptions,
138
            $this->makePricingOptionForCurrencyOverride($options->currencyOverride)
139
        );
140
141
        $priceOptions = $this->mergeOptions(
142
            $priceOptions,
143
            $this->makePricingOptionForSelection($options->multiReferences)
144
        );
145
146
        $priceOptions = $this->mergeOptions(
147
            $priceOptions,
148
            $this->makeBreakpointOptions(
149
                $options->forceBreakPointRefs,
150
                $options->noBreakPointRefs
151
            )
152
        );
153
154
        $priceOptions = $this->mergeOptions(
155
            $priceOptions,
156
            $this->loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs)
157
        );
158
159
        $priceOptions = $this->mergeOptions(
160
            $priceOptions,
161
            $this->loadPointOverrides(
162
                $options->pointOfSaleOverride,
163
                $options->pointOfTicketingOverride
164
            )
165
        );
166
167
        $priceOptions = $this->mergeOptions(
168
            $priceOptions,
169
            $this->loadWaiverCode($options->waiverCode)
170
        );
171
172
        $priceOptions = $this->mergeOptions(
173
            $priceOptions,
174
            $this->loadOverrideReusableAmount($options->overrideReusableAmountRefs)
175
        );
176
177
        $priceOptions = $this->mergeOptions(
178
            $priceOptions,
179
            $this->makeOverrideOptions($options->overrideOptions, $priceOptions)
180
        );
181
182
        // All options processed, no options found:
183
        if (empty($priceOptions)) {
184
            $priceOptions[] = new PricingOption(PricingOptionKey::OPTION_NO_OPTION);
185
        }
186
187
        return $priceOptions;
188
    }
189
190
191
    /**
192
     * Merges Pricing options
193
     *
194
     * @param PricingOption[] $existingOptions
195
     * @param PricingOption[] $newOptions
196
     * @return PricingOption[] merged array
197
     */
198
    protected function mergeOptions($existingOptions, $newOptions)
199
    {
200
        if (!empty($newOptions)) {
201
            $existingOptions = array_merge(
202
                $existingOptions,
203
                $newOptions
204
            );
205
        }
206
207
        return $existingOptions;
208
    }
209
210
    /**
211
     * @param string|null $carrier
212
     * @param string $pricingOptionKey PricingOptionKey::OPTION_*
213
     * @return PricingOption[]
214
     */
215
    protected function makePricingOptionForCarrier($carrier, $pricingOptionKey)
216
    {
217
        $opt = [];
218
219
        if ($carrier !== null) {
220
            $po = new PricingOption($pricingOptionKey);
221
222
            $po->carrierInformation = new CarrierInformation($carrier);
223
224
            $opt[] = $po;
225
        }
226
227
        return $opt;
228
    }
229
230
    /**
231
     * @param MultiRefOpt[] $multiReferences
232
     * @return PricingOption[]
233
     */
234
    protected function makePricingOptionForSelection($multiReferences)
235
    {
236
        $opt = [];
237
238
        foreach ($multiReferences as $multiReference) {
239
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
240
                $multiReference->references,
241
                PricingOptionKey::OPTION_PAX_SEG_LINE_TST_SELECTION
242
            );
243
        }
244
245
        return $opt;
246
    }
247
248
249
    /**
250
     * @param PaxSegRef[] $forceBreakPointRefs
251
     * @param PaxSegRef[] $noBreakPointRefs
252
     * @return PricingOption[]
253
     */
254
    protected function makeBreakpointOptions($forceBreakPointRefs, $noBreakPointRefs)
255
    {
256
        $opt = [];
257
258
        if (!empty($forceBreakPointRefs)) {
259
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
260
                $forceBreakPointRefs,
261
                PricingOptionKey::OPTION_FORCE_FEE_BREAK_POINT
262
            );
263
        }
264
265
        if (!empty($noBreakPointRefs)) {
266
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
267
                $noBreakPointRefs,
268
                PricingOptionKey::OPTION_NO_BREAKPOINT
269
            );
270
        }
271
272
        return $opt;
273
    }
274
275
    /**
276
     * @param PaxSegRef[] $refs
277
     * @param string $pricingOptionKey PricingOptionKey::OPTION_*
278
     * @return PricingOption
279
     */
280
    protected function makePricingOptionWithPaxSegTstRefs($refs, $pricingOptionKey)
281
    {
282
        $po = new PricingOption($pricingOptionKey);
283
284
        $po->paxSegTstReference = new PaxSegTstReference($refs);
285
286
        return $po;
287
    }
288
289
    /**
290
     * Load corporate unifares
291
     *
292
     * @param string[] $corporateUniFares
293
     * @param AwardPricing|null $awardPricing
294
     * @return PricingOption[]
295
     */
296
    protected function loadCorpUniFares($corporateUniFares, $awardPricing)
297
    {
298
        $opt = [];
299
300
        if (!empty($corporateUniFares)) {
301
            $po = new PricingOption(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
302
            $po->optionDetail = new OptionDetail($corporateUniFares);
303
            $opt[] = $po;
304
305
            if (!empty($awardPricing)) {
306
                $opt[] = $this->loadAwardPricing($awardPricing);
307
            }
308
        }
309
310
        return $opt;
311
    }
312
313
    /**
314
     * @param AwardPricing $awardPricing
315
     * @return PricingOption
316
     */
317 View Code Duplication
    protected 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...
318
    {
319
        $po = new PricingOption(PricingOptionKey::OPTION_AWARD);
320
321
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
322
323
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
324
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
325
            $awardPricing->tierLevel
326
        );
327
328
        return $po;
329
    }
330
331
    /**
332
     * @param FareBasis[] $pricingsFareBasis
333
     * @return PricingOption[]
334
     */
335 View Code Duplication
    protected 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...
336
    {
337
        $opt = [];
338
339
        if ($pricingsFareBasis !== null) {
340
            foreach ($pricingsFareBasis as $pricingFareBasis) {
341
                $po = new PricingOption(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
342
343
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
344
                $po->optionDetail = new OptionDetail(
345
                    $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...
346
                );
347
348
                //Support for legacy segmentReference to be removed when breaking BC:
349
                $po->paxSegTstReference = new PaxSegTstReference(
350
                    $pricingFareBasis->references,
351
                    $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...
352
                );
353
354
                $opt[] = $po;
355
            }
356
        }
357
358
        return $opt;
359
    }
360
361
    /**
362
     * @param Tax[] $taxes
363
     * @return PricingOption[]
364
     */
365 View Code Duplication
    protected 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...
366
    {
367
        $opt = [];
368
369
        if (!empty($taxes)) {
370
            $po = new PricingOption(PricingOptionKey::OPTION_ADD_TAX);
371
372
            foreach ($taxes as $tax) {
373
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
374
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
375
376
                $po->taxInformation[] = new TaxInformation(
377
                    $tax->countryCode,
378
                    $tax->taxNature,
379
                    $qualifier,
380
                    $rate
381
                );
382
            }
383
            $opt[] = $po;
384
        }
385
386
        return $opt;
387
    }
388
389
    /**
390
     * @param ExemptTax[] $exemptTaxes
391
     * @return PricingOption[]
392
     */
393 View Code Duplication
    protected 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...
394
    {
395
        $opt = [];
396
397
        if (!empty($exemptTaxes)) {
398
            $po = new PricingOption(PricingOptionKey::OPTION_EXEMPT_TAXES);
399
400
            foreach ($exemptTaxes as $tax) {
401
                $po->taxInformation[] = new TaxInformation(
402
                    $tax->countryCode,
403
                    $tax->taxNature
404
                );
405
            }
406
407
            $opt[] = $po;
408
        }
409
410
        return $opt;
411
    }
412
413
    /**
414
     * @param string|null $currency
415
     * @return PricingOption[]
416
     */
417 View Code Duplication
    protected 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...
418
    {
419
        $opt = [];
420
421
        if ($currency !== null) {
422
            $po = new PricingOption(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
423
424
            $po->currency = new Currency($currency);
425
426
            $opt[] = $po;
427
        }
428
429
        return $opt;
430
    }
431
432
    /**
433
     * @param string[] $paxDiscount
434
     * @param PaxSegRef[] $paxDiscountCodeRefs
435
     * @return PricingOption[]
436
     */
437 View Code Duplication
    protected 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...
438
    {
439
        $opt = [];
440
441
        if (!empty($paxDiscount)) {
442
            $po = new PricingOption(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
443
444
            $po->penDisInformation = new PenDisInformation(
445
                PenDisInformation::QUAL_DISCOUNT,
446
                $paxDiscount
447
            );
448
449
            if (!empty($paxDiscountCodeRefs)) {
450
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
451
            }
452
453
            $opt[] = $po;
454
        }
455
456
        return $opt;
457
    }
458
459
    /**
460
     * @param string|null $posOverride
461
     * @param string|null $potOverride
462
     * @return PricingOption[]
463
     */
464 View Code Duplication
    protected 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...
465
    {
466
        $opt = [];
467
468
        if (!empty($posOverride)) {
469
            $po = new PricingOption(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
470
471
            $po->locationInformation = new LocationInformation(
472
                LocationInformation::TYPE_POINT_OF_SALE,
473
                $posOverride
474
            );
475
476
            $opt[] = $po;
477
        }
478
479
        if (!empty($potOverride)) {
480
            $po2 = new PricingOption(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
481
482
            $po2->locationInformation = new LocationInformation(
483
                LocationInformation::TYPE_POINT_OF_TICKETING,
484
                $potOverride
485
            );
486
487
            $opt[] = $po2;
488
        }
489
490
        return $opt;
491
    }
492
493
494
    /**
495
     * @param string|null $waiverCode
496
     * @return PricingOption[]
497
     */
498 View Code Duplication
    protected function loadWaiverCode($waiverCode)
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
        $opt = [];
501
502
        if (!empty($waiverCode)) {
503
            $po = new PricingOption(PricingOptionKey::OPTION_WAIVER_OPTION);
504
505
            $po->optionDetail = new OptionDetail($waiverCode);
506
507
            $opt[] = $po;
508
        }
509
510
        return $opt;
511
    }
512
513
    /**
514
     * @param PaxSegRef[] $overrideReusableAmountRefs
515
     * @return PricingOption[]
516
     */
517
    protected function loadOverrideReusableAmount($overrideReusableAmountRefs)
518
    {
519
        $opt = [];
520
521
        if (!empty($overrideReusableAmountRefs)) {
522
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
523
                $overrideReusableAmountRefs,
524
                PricingOptionKey::OPTION_OVERRIDE_REUSABLE_AMOUNT
525
            );
526
        }
527
528
        return $opt;
529
    }
530
531
    /**
532
     * @param string[] $overrideOptions
533
     * @param PricingOption[] $priceOptions
534
     * @return PricingOption[]
535
     */
536
    protected function makeOverrideOptions($overrideOptions, $priceOptions)
537
    {
538
        $opt = [];
539
540
        foreach ($overrideOptions as $overrideOption) {
541
            if (!$this->hasPricingOption($overrideOption, $priceOptions)) {
542
                $opt[] = new PricingOption($overrideOption);
543
            }
544
        }
545
546
        return $opt;
547
    }
548
549
    /**
550
     * Avoid double pricing groups when combining an explicitly provided override option with a specific parameter
551
     * that uses the same override option.
552
     *
553
     * @param string $optionKey
554
     * @param PricingOption[] $priceOptions
555
     * @return bool
556
     */
557 View Code Duplication
    protected function hasPricingOption($optionKey, $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...
558
    {
559
        $found = false;
560
561
        foreach ($priceOptions as $pog) {
562
            if ($pog->pricingOptionKey->pricingOptionKey === $optionKey) {
563
                $found = true;
564
            }
565
        }
566
567
        return $found;
568
    }
569
}
570