Passed
Push — master ( 4f4e52...cfbd52 )
by Dieter
07:23
created

makePricingOptionFareBasisOverride()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 25
Ratio 100 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 0
Metric Value
dl 25
loc 25
ccs 16
cts 16
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 1
crap 3
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 19
    public function __construct($options)
72
    {
73 19
        if (!is_null($options)) {
74 19
            $this->loadExchangeInfo($options->exchangeInfo);
75
76 19
            $this->pricingOption = $this->loadPricingOptionsFromRequestOptions($options);
77 19
        }
78 19
    }
79
80
    /**
81
     * @param ExchangeInfoOptions[] $exchangeInfo
82
     */
83 19
    protected function loadExchangeInfo($exchangeInfo)
84
    {
85 19
        foreach ($exchangeInfo as $info) {
86 19
            if ($info instanceof ExchangeInfoOptions) {
87 19
                $this->exchangeInformationGroup[] = new ExchangeInformationGroup($info);
88 19
            }
89 19
        }
90 19
    }
91
92
    /**
93
     * @param TicketRepricePnrWithBookingClassOptions $options
94
     * @return PricingOption[]
95
     */
96 19
    protected function loadPricingOptionsFromRequestOptions(TicketRepricePnrWithBookingClassOptions $options)
97
    {
98 19
        $priceOptions = [];
99
100 19
        $priceOptions = $this->mergeOptions(
101 19
            $priceOptions,
102 19
            $this->makePricingOptionForCarrier(
103 19
                $options->validatingCarrier,
104
                PricingOptionKey::OPTION_VALIDATING_CARRIER
105 19
            )
106 19
        );
107
108 19
        $priceOptions = $this->mergeOptions(
109 19
            $priceOptions,
110 19
            $this->makePricingOptionForCarrier(
111 19
                $options->controllingCarrier,
112
                PricingOptionKey::OPTION_OVERRIDE_CONTROLLING_CARRIER
113 19
            )
114 19
        );
115
116 19
        $priceOptions = $this->mergeOptions(
117 19
            $priceOptions,
118 19
            $this->loadCorpUniFares($options->corporateUniFares, $options->awardPricing)
119 19
        );
120
121 19
        $priceOptions = $this->mergeOptions(
122 19
            $priceOptions,
123 19
            $this->makePricingOptionFareBasisOverride($options->pricingsFareBasis)
124 19
        );
125
126 19
        $priceOptions = $this->mergeOptions(
127 19
            $priceOptions,
128 19
            $this->loadTaxes($options->taxes)
129 19
        );
130
131 19
        $priceOptions = $this->mergeOptions(
132 19
            $priceOptions,
133 19
            $this->loadExemptTaxes($options->exemptTaxes)
134 19
        );
135
136 19
        $priceOptions = $this->mergeOptions(
137 19
            $priceOptions,
138 19
            $this->makePricingOptionForCurrencyOverride($options->currencyOverride)
139 19
        );
140
141 19
        $priceOptions = $this->mergeOptions(
142 19
            $priceOptions,
143 19
            $this->makePricingOptionForSelection($options->multiReferences)
144 19
        );
145
146 19
        $priceOptions = $this->mergeOptions(
147 19
            $priceOptions,
148 19
            $this->makeBreakpointOptions(
149 19
                $options->forceBreakPointRefs,
150 19
                $options->noBreakPointRefs
151 19
            )
152 19
        );
153
154 19
        $priceOptions = $this->mergeOptions(
155 19
            $priceOptions,
156 19
            $this->loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs)
157 19
        );
158
159 19
        $priceOptions = $this->mergeOptions(
160 19
            $priceOptions,
161 19
            $this->loadPointOverrides(
162 19
                $options->pointOfSaleOverride,
163 19
                $options->pointOfTicketingOverride
164 19
            )
165 19
        );
166
167 19
        $priceOptions = $this->mergeOptions(
168 19
            $priceOptions,
169 19
            $this->loadWaiverCode($options->waiverCode)
170 19
        );
171
172 19
        $priceOptions = $this->mergeOptions(
173 19
            $priceOptions,
174 19
            $this->loadOverrideReusableAmount($options->overrideReusableAmountRefs)
175 19
        );
176
177 19
        $priceOptions = $this->mergeOptions(
178 19
            $priceOptions,
179 19
            $this->makeOverrideOptions($options->overrideOptions, $priceOptions)
180 19
        );
181
182
        // All options processed, no options found:
183 19
        if (empty($priceOptions)) {
184 1
            $priceOptions[] = new PricingOption(PricingOptionKey::OPTION_NO_OPTION);
185 1
        }
186
187 19
        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 19
    protected function mergeOptions($existingOptions, $newOptions)
199
    {
200 19
        if (!empty($newOptions)) {
201 18
            $existingOptions = array_merge(
202 18
                $existingOptions,
203
                $newOptions
204 18
            );
205 18
        }
206
207 19
        return $existingOptions;
208
    }
209
210
    /**
211
     * @param string|null $carrier
212
     * @param string $pricingOptionKey PricingOptionKey::OPTION_*
213
     * @return PricingOption[]
214
     */
215 19
    protected function makePricingOptionForCarrier($carrier, $pricingOptionKey)
216
    {
217 19
        $opt = [];
218
219 19
        if ($carrier !== null) {
220 2
            $po = new PricingOption($pricingOptionKey);
221
222 2
            $po->carrierInformation = new CarrierInformation($carrier);
223
224 2
            $opt[] = $po;
225 2
        }
226
227 19
        return $opt;
228
    }
229
230
    /**
231
     * @param MultiRefOpt[] $multiReferences
232
     * @return PricingOption[]
233
     */
234 19
    protected function makePricingOptionForSelection($multiReferences)
235
    {
236 19
        $opt = [];
237
238 19
        foreach ($multiReferences as $multiReference) {
239 4
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
240 4
                $multiReference->references,
241
                PricingOptionKey::OPTION_PAX_SEG_LINE_TST_SELECTION
242 4
            );
243 19
        }
244
245 19
        return $opt;
246
    }
247
248
249
    /**
250
     * @param PaxSegRef[] $forceBreakPointRefs
251
     * @param PaxSegRef[] $noBreakPointRefs
252
     * @return PricingOption[]
253
     */
254 19
    protected function makeBreakpointOptions($forceBreakPointRefs, $noBreakPointRefs)
255
    {
256 19
        $opt = [];
257
258 19
        if (!empty($forceBreakPointRefs)) {
259 1
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
260 1
                $forceBreakPointRefs,
261
                PricingOptionKey::OPTION_FORCE_FEE_BREAK_POINT
262 1
            );
263 1
        }
264
265 19
        if (!empty($noBreakPointRefs)) {
266 1
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
267 1
                $noBreakPointRefs,
268
                PricingOptionKey::OPTION_NO_BREAKPOINT
269 1
            );
270 1
        }
271
272 19
        return $opt;
273
    }
274
275
    /**
276
     * @param PaxSegRef[] $refs
277
     * @param string $pricingOptionKey PricingOptionKey::OPTION_*
278
     * @return PricingOption
279
     */
280 7
    protected function makePricingOptionWithPaxSegTstRefs($refs, $pricingOptionKey)
281
    {
282 7
        $po = new PricingOption($pricingOptionKey);
283
284 7
        $po->paxSegTstReference = new PaxSegTstReference($refs);
285
286 7
        return $po;
287
    }
288
289
    /**
290
     * Load corporate unifares
291
     *
292
     * @param string[] $corporateUniFares
293
     * @param AwardPricing|null $awardPricing
294
     * @return PricingOption[]
295
     */
296 19
    protected function loadCorpUniFares($corporateUniFares, $awardPricing)
297
    {
298 19
        $opt = [];
299
300 19
        if (!empty($corporateUniFares)) {
301 1
            $po = new PricingOption(PricingOptionKey::OPTION_CORPORATE_UNIFARES);
302 1
            $po->optionDetail = new OptionDetail($corporateUniFares);
303 1
            $opt[] = $po;
304
305 1
            if (!empty($awardPricing)) {
306 1
                $opt[] = $this->loadAwardPricing($awardPricing);
307 1
            }
308 1
        }
309
310 19
        return $opt;
311
    }
312
313
    /**
314
     * @param AwardPricing $awardPricing
315
     * @return PricingOption
316
     */
317 1 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 1
        $po = new PricingOption(PricingOptionKey::OPTION_AWARD);
320
321 1
        $po->carrierInformation = new CarrierInformation($awardPricing->carrier);
322
323 1
        $po->frequentFlyerInformation = new FrequentFlyerInformation();
324 1
        $po->frequentFlyerInformation->frequentTravellerDetails[] = new FrequentTravellerDetails(
325 1
            $awardPricing->tierLevel
326 1
        );
327
328 1
        return $po;
329
    }
330
331
    /**
332
     * @param FareBasis[] $pricingsFareBasis
333
     * @return PricingOption[]
334
     */
335 19 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 19
        $opt = [];
338
339 19
        if ($pricingsFareBasis !== null) {
340 19
            foreach ($pricingsFareBasis as $pricingFareBasis) {
341 2
                $po = new PricingOption(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
342
343
                //Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
344 2
                $po->optionDetail = new OptionDetail(
345 2
                    $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 2
                );
347
348
                //Support for legacy segmentReference to be removed when breaking BC:
349 2
                $po->paxSegTstReference = new PaxSegTstReference(
350 2
                    $pricingFareBasis->references,
351 2
                    $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 2
                );
353
354 2
                $opt[] = $po;
355 19
            }
356 19
        }
357
358 19
        return $opt;
359
    }
360
361
    /**
362
     * @param Tax[] $taxes
363
     * @return PricingOption[]
364
     */
365 19 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 19
        $opt = [];
368
369 19
        if (!empty($taxes)) {
370 1
            $po = new PricingOption(PricingOptionKey::OPTION_ADD_TAX);
371
372 1
            foreach ($taxes as $tax) {
373 1
                $qualifier = (!empty($tax->amount)) ? TaxData::QUALIFIER_AMOUNT : TaxData::QUALIFIER_PERCENTAGE;
374 1
                $rate = (!empty($tax->amount)) ? $tax->amount : $tax->percentage;
375
376 1
                $po->taxInformation[] = new TaxInformation(
377 1
                    $tax->countryCode,
378 1
                    $tax->taxNature,
379 1
                    $qualifier,
380
                    $rate
381 1
                );
382 1
            }
383 1
            $opt[] = $po;
384 1
        }
385
386 19
        return $opt;
387
    }
388
389
    /**
390
     * @param ExemptTax[] $exemptTaxes
391
     * @return PricingOption[]
392
     */
393 19 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 19
        $opt = [];
396
397 19
        if (!empty($exemptTaxes)) {
398 1
            $po = new PricingOption(PricingOptionKey::OPTION_EXEMPT_TAXES);
399
400 1
            foreach ($exemptTaxes as $tax) {
401 1
                $po->taxInformation[] = new TaxInformation(
402 1
                    $tax->countryCode,
403 1
                    $tax->taxNature
404 1
                );
405 1
            }
406
407 1
            $opt[] = $po;
408 1
        }
409
410 19
        return $opt;
411
    }
412
413
    /**
414
     * @param string|null $currency
415
     * @return PricingOption[]
416
     */
417 19 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 19
        $opt = [];
420
421 19
        if ($currency !== null) {
422 2
            $po = new PricingOption(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);
423
424 2
            $po->currency = new Currency($currency);
425
426 2
            $opt[] = $po;
427 2
        }
428
429 19
        return $opt;
430
    }
431
432
    /**
433
     * @param string[] $paxDiscount
434
     * @param PaxSegRef[] $paxDiscountCodeRefs
435
     * @return PricingOption[]
436
     */
437 19 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 19
        $opt = [];
440
441 19
        if (!empty($paxDiscount)) {
442 1
            $po = new PricingOption(PricingOptionKey::OPTION_PASSENGER_DISCOUNT_PTC);
443
444 1
            $po->penDisInformation = new PenDisInformation(
445 1
                PenDisInformation::QUAL_DISCOUNT,
446
                $paxDiscount
447 1
            );
448
449 1
            if (!empty($paxDiscountCodeRefs)) {
450 1
                $po->paxSegTstReference = new PaxSegTstReference($paxDiscountCodeRefs);
451 1
            }
452
453 1
            $opt[] = $po;
454 1
        }
455
456 19
        return $opt;
457
    }
458
459
    /**
460
     * @param string|null $posOverride
461
     * @param string|null $potOverride
462
     * @return PricingOption[]
463
     */
464 19 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 19
        $opt = [];
467
468 19
        if (!empty($posOverride)) {
469 1
            $po = new PricingOption(PricingOptionKey::OPTION_POINT_OF_SALE_OVERRIDE);
470
471 1
            $po->locationInformation = new LocationInformation(
472 1
                LocationInformation::TYPE_POINT_OF_SALE,
473
                $posOverride
474 1
            );
475
476 1
            $opt[] = $po;
477 1
        }
478
479 19
        if (!empty($potOverride)) {
480 1
            $po2 = new PricingOption(PricingOptionKey::OPTION_POINT_OF_TICKETING_OVERRIDE);
481
482 1
            $po2->locationInformation = new LocationInformation(
483 1
                LocationInformation::TYPE_POINT_OF_TICKETING,
484
                $potOverride
485 1
            );
486
487 1
            $opt[] = $po2;
488 1
        }
489
490 19
        return $opt;
491
    }
492
493
494
    /**
495
     * @param string|null $waiverCode
496
     * @return PricingOption[]
497
     */
498 19 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 19
        $opt = [];
501
502 19
        if (!empty($waiverCode)) {
503 1
            $po = new PricingOption(PricingOptionKey::OPTION_WAIVER_OPTION);
504
505 1
            $po->optionDetail = new OptionDetail($waiverCode);
506
507 1
            $opt[] = $po;
508 1
        }
509
510 19
        return $opt;
511
    }
512
513
    /**
514
     * @param PaxSegRef[] $overrideReusableAmountRefs
515
     * @return PricingOption[]
516
     */
517 19
    protected function loadOverrideReusableAmount($overrideReusableAmountRefs)
518
    {
519 19
        $opt = [];
520
521 19
        if (!empty($overrideReusableAmountRefs)) {
522 1
            $opt[] = $this->makePricingOptionWithPaxSegTstRefs(
523 1
                $overrideReusableAmountRefs,
524
                PricingOptionKey::OPTION_OVERRIDE_REUSABLE_AMOUNT
525 1
            );
526 1
        }
527
528 19
        return $opt;
529
    }
530
531
    /**
532
     * @param string[] $overrideOptions
533
     * @param PricingOption[] $priceOptions
534
     * @return PricingOption[]
535
     */
536 19
    protected function makeOverrideOptions($overrideOptions, $priceOptions)
537
    {
538 19
        $opt = [];
539
540 19
        foreach ($overrideOptions as $overrideOption) {
541 2
            if (!$this->hasPricingOption($overrideOption, $priceOptions)) {
542 2
                $opt[] = new PricingOption($overrideOption);
543 2
            }
544 19
        }
545
546 19
        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 2 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 2
        $found = false;
560
561 2
        foreach ($priceOptions as $pog) {
562 1
            if ($pog->pricingOptionKey->pricingOptionKey === $optionKey) {
563 1
                $found = true;
564 1
            }
565 2
        }
566
567 2
        return $found;
568
    }
569
}
570