Completed
Push — master ( e5baa0...e98dc1 )
by Dieter
07:25
created

PricePNRWithBookingClass12::loadOverrideOptions()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 8
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\Fare;
24
25
use Amadeus\Client\RequestOptions\Fare\PricePnr\AwardPricing;
26
use Amadeus\Client\RequestOptions\Fare\PricePnr\ExemptTax;
27
use Amadeus\Client\RequestOptions\Fare\PricePnr\PaxSegRef;
28
use Amadeus\Client\RequestOptions\Fare\PricePnr\Tax;
29
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
30
use Amadeus\Client\Struct\BaseWsMessage;
31
use Amadeus\Client\Struct\Fare\PricePnr12\AttributeDetails;
32
use Amadeus\Client\Struct\Fare\PricePnr12\CarrierAgreements;
33
use Amadeus\Client\Struct\Fare\PricePnr12\CityDetail;
34
use Amadeus\Client\Struct\Fare\PricePnr12\CurrencyOverride;
35
use Amadeus\Client\Struct\Fare\PricePnr12\DateOverride;
36
use Amadeus\Client\Struct\Fare\PricePnr12\DiscountInformation;
37
use Amadeus\Client\Struct\Fare\PricePnr12\FrequentFlyerInformation;
38
use Amadeus\Client\Struct\Fare\PricePnr12\OverrideInformation;
39
use Amadeus\Client\Struct\Fare\PricePnr12\PenDisData;
40
use Amadeus\Client\Struct\Fare\PricePnr12\PenDisInformation;
41
use Amadeus\Client\Struct\Fare\PricePnr12\PricingFareBase;
42
use Amadeus\Client\Struct\Fare\PricePnr12\RefDetails;
43
use Amadeus\Client\Struct\Fare\PricePnr12\ReferenceQualifier;
44
use Amadeus\Client\Struct\Fare\PricePnr12\TaxDetails;
45
use Amadeus\Client\Struct\Fare\PricePnr12\ValidatingCarrier;
46
use Amadeus\Client\Struct\OptionNotSupportedException;
47
48
/**
49
 * Fare_PricePNRWithBookingClass v 12 and lower structure
50
 *
51
 * @package Amadeus\Client\Struct\Fare
52
 * @author dieter <[email protected]>
53
 */
54
class PricePNRWithBookingClass12 extends BaseWsMessage
55
{
56
    public $pnrLocatorData;
57
58
    /**
59
     * @var PricePnr12\PaxSegReference
60
     */
61
    public $paxSegReference;
62
63
    /**
64
     * @var PricePnr12\OverrideInformation
65
     */
66
    public $overrideInformation;
67
68
    /**
69
     * @var PricePnr12\DateOverride
70
     */
71
    public $dateOverride;
72
73
    /**
74
     * @var PricePnr12\ValidatingCarrier
75
     */
76
    public $validatingCarrier;
77
78
    /**
79
     * @var PricePnr12\CityOverride
80
     */
81
    public $cityOverride;
82
83
    /**
84
     * @var PricePnr12\CurrencyOverride
85
     */
86
    public $currencyOverride;
87
88
    /**
89
     * @var PricePnr12\TaxDetails[]
90
     */
91
    public $taxDetails = [];
92
93
    /**
94
     * @var PricePnr12\DiscountInformation[]
95
     */
96
    public $discountInformation = [];
97
    /**
98
     * @var PricePnr12\PricingFareBase[]
99
     */
100
    public $pricingFareBase = [];
101
102
    public $flightInformation;
103
104
    public $openSegmentsInformation;
105
106
    public $bookingClassSelection;
107
108
    public $fopInformation;
109
110
    /**
111
     * @var CarrierAgreements
112
     */
113
    public $carrierAgreements;
114
115
    /**
116
     * @var FrequentFlyerInformation
117
     */
118
    public $frequentFlyerInformation;
119
120
    public $instantPricingOption;
121
122
    /**
123
     * PricePNRWithBookingClass12 constructor.
124
     *
125
     * @param FarePricePnrWithBookingClassOptions $options
126
     */
127
    public function __construct(FarePricePnrWithBookingClassOptions $options)
128
    {
129
        $this->checkUnsupportedOptions($options);
130
131
        $this->overrideInformation = new OverrideInformation();
132
133
        $this->loadOverrideOptions($options);
134
135
        $this->loadValidatingCarrier($options);
136
137
        $this->loadFareBasis($options);
138
139
        $this->loadCorporateFares($options);
140
141
        $this->loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs);
142
143
        $this->loadOverrideLocations($options);
144
145
        $this->loadTaxOptions($options);
146
147
        $this->loadReferences($options->references);
148
149
        $this->loadPastDate($options->pastDatePricing);
150
151
        //No Options?
152
        if (empty($this->overrideInformation->attributeDetails)) {
153
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
154
                AttributeDetails::OVERRIDE_NO_OPTION
155
            );
156
        }
157
    }
158
159
    /**
160
     * @param FarePricePnrWithBookingClassOptions $options
161
     * @throws OptionNotSupportedException
162
     */
163
    protected function checkUnsupportedOptions(FarePricePnrWithBookingClassOptions $options)
164
    {
165
        if (!empty($options->obFees)) {
166
            throw new OptionNotSupportedException('OB Fees option not supported in version 12 or lower');
167
        }
168
169
        if (!empty($options->pricingLogic)) {
170
            throw new OptionNotSupportedException('Pricing Logic option not supported in version 12 or lower');
171
        }
172
    }
173
174
    /**
175
     * @param FarePricePnrWithBookingClassOptions $options
176
     */
177
    protected function loadOverrideOptions(FarePricePnrWithBookingClassOptions $options)
178
    {
179
        if (count($options->overrideOptions) !== 0) {
180
            foreach ($options->overrideOptions as $overrideOption) {
181
                $this->overrideInformation->attributeDetails[] = new AttributeDetails($overrideOption);
182
            }
183
        }
184
185
        if (!empty($options->currencyOverride)) {
186
            $this->currencyOverride = new CurrencyOverride($options->currencyOverride);
187
        }
188
189
        if (!empty($options->ticketType)) {
190
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
191
                $this->convertTicketType($options->ticketType)
192
            );
193
        }
194
    }
195
196
    /**
197
     * Convert new codes (Price PNR version 13+) to old format
198
     *
199
     * @param string $optionsTicketType
200
     * @return string|null
201
     */
202
    protected function convertTicketType($optionsTicketType)
203
    {
204
        $converted = null;
205
206
        $map = [
207
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_ELECTRONIC => AttributeDetails::OVERRIDE_ELECTRONIC_TICKET,
208
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_PAPER => AttributeDetails::OVERRIDE_PAPER_TICKET,
209
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_BOTH => AttributeDetails::OVERRIDE_BOTH_TICKET,
210
        ];
211
212
        if (array_key_exists($optionsTicketType, $map)) {
213
            $converted = $map[$optionsTicketType];
214
        }
215
216
        return $converted;
217
    }
218
219
    /**
220
     * @param FarePricePnrWithBookingClassOptions $options
221
     */
222
    protected function loadCorporateFares(FarePricePnrWithBookingClassOptions $options)
223
    {
224
        if ($options->corporateNegoFare !== null) {
225
            $this->loadCorporateNegoFare($options->corporateNegoFare);
226
        }
227
228
        if (!empty($options->corporateUniFares)) {
229
            $this->loadCorporateUniFares($options->corporateUniFares);
230
231
            if (!empty($options->awardPricing)) {
232
                $this->loadAwardPricing($options->awardPricing);
233
            }
234
        }
235
    }
236
237
    /**
238
     * @param string $corporateNegoFare
239
     */
240
    protected function loadCorporateNegoFare($corporateNegoFare)
241
    {
242
        $this->overrideInformation->attributeDetails[] = new AttributeDetails(
243
            AttributeDetails::OVERRIDE_FARETYPE_CORPNR,
244
            $corporateNegoFare
245
        );
246
    }
247
248
    /**
249
     * @param string[] $corporateUniFares
250
     */
251
    protected function loadCorporateUniFares($corporateUniFares)
252
    {
253
        foreach ($corporateUniFares as $corporateUniFare) {
254
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
255
                AttributeDetails::OVERRIDE_FARETYPE_CORPUNI,
256
                $corporateUniFare
257
            );
258
        }
259
    }
260
261
    /**
262
     * @param AwardPricing $awardPricing
263
     */
264
    protected function loadAwardPricing($awardPricing)
265
    {
266
        $this->carrierAgreements = new CarrierAgreements($awardPricing->carrier);
267
        $this->frequentFlyerInformation = new FrequentFlyerInformation($awardPricing->tierLevel);
268
    }
269
270
    /**
271
     * @param FarePricePnrWithBookingClassOptions $options
272
     *
273
     */
274
    protected function loadOverrideLocations(FarePricePnrWithBookingClassOptions $options)
275
    {
276
        if (!empty($options->pointOfSaleOverride)) {
277
            $this->cityOverride = new PricePnr12\CityOverride(
278
                $options->pointOfSaleOverride,
279
                CityDetail::QUAL_POINT_OF_SALE
280
            );
281
        }
282
283
        if (!empty($options->pointOfTicketingOverride)) {
284
            if (empty($this->cityOverride)) {
285
                $this->cityOverride = new PricePnr12\CityOverride();
286
            }
287
            $this->cityOverride->cityDetail[] = new PricePnr12\CityDetail(
288
                $options->pointOfTicketingOverride,
289
                CityDetail::QUAL_POINT_OF_TICKETING
290
            );
291
        }
292
    }
293
294
    /**
295
     * @param FarePricePnrWithBookingClassOptions $options
296
     */
297
    protected function loadValidatingCarrier(FarePricePnrWithBookingClassOptions $options)
298
    {
299
        if (is_string($options->validatingCarrier)) {
300
            $this->validatingCarrier = new ValidatingCarrier($options->validatingCarrier);
301
        }
302
    }
303
304
    /**
305
     * @param FarePricePnrWithBookingClassOptions $options
306
     *
307
     */
308
    protected function loadFareBasis(FarePricePnrWithBookingClassOptions $options)
309
    {
310
        $short = AttributeDetails::OVERRIDE_FAREBASIS; //Short var name because I get complaints from phpcs. No judging.
311
        if (in_array($short, $options->overrideOptions) && !empty($options->pricingsFareBasis)) {
312
            foreach ($options->pricingsFareBasis as $pricingFareBasis) {
313
                $this->pricingFareBase[] = new PricingFareBase($pricingFareBasis);
314
            }
315
        }
316
    }
317
318
    /**
319
     * @param FarePricePnrWithBookingClassOptions $options
320
     *
321
     */
322
    protected function loadTaxOptions(FarePricePnrWithBookingClassOptions $options)
323
    {
324
        if (!empty($options->taxes)) {
325
            $this->loadTaxes($options->taxes);
326
        }
327
328
        if (!empty($options->exemptTaxes)) {
329
            $this->loadExemptTaxes($options->exemptTaxes);
330
        }
331
    }
332
333
    /**
334
     * @param Tax[] $taxes
335
     */
336
    protected function loadTaxes($taxes)
337
    {
338
        foreach ($taxes as $tax) {
339
            $this->taxDetails[] = new TaxDetails($tax);
340
        }
341
    }
342
343
    /**
344
     * @param ExemptTax[] $exemptTaxes
345
     */
346
    protected function loadExemptTaxes($exemptTaxes)
347
    {
348
        foreach ($exemptTaxes as $exemptTax) {
349
            $this->taxDetails[] = new TaxDetails($exemptTax);
350
        }
351
    }
352
353
    /**
354
     * @param string[] $paxDiscountCodes
355
     * @param PaxSegRef[] $refs
356
     */
357
    protected function loadPaxDiscount($paxDiscountCodes, $refs)
358
    {
359
        if (!empty($paxDiscountCodes)) {
360
            $tmp = new DiscountInformation();
361
            $tmp->penDisInformation = new PenDisInformation();
362
            $tmp->penDisInformation->infoQualifier = PenDisInformation::QUAL_DISCOUNT;
363
364
            foreach ($paxDiscountCodes as $discountCode) {
365
                $tmp->penDisInformation->penDisData[] = new PenDisData($discountCode);
366
            }
367
368 View Code Duplication
            if (!empty($refs)) {
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...
369
                $tmp->referenceQualifier = new ReferenceQualifier();
370
371
                foreach ($refs as $ref) {
372
                    $tmp->referenceQualifier->refDetails[] = new RefDetails($ref->reference, $ref->type);
373
                }
374
            }
375
376
            $this->discountInformation[] = $tmp;
377
        }
378
    }
379
380
    /**
381
     * @param PaxSegRef[] $references
382
     */
383
    protected function loadReferences($references)
384
    {
385 View Code Duplication
        if (!empty($references)) {
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...
386
            $this->paxSegReference = new PricePnr12\PaxSegReference();
387
388
            foreach ($references as $ref) {
389
                $this->paxSegReference->refDetails[] = new RefDetails(
390
                    $ref->reference,
391
                    $ref->type
392
                );
393
            }
394
        }
395
    }
396
397
    /**
398
     * @param \DateTime|null $pastDate
399
     */
400
    protected function loadPastDate($pastDate)
401
    {
402
        if ($pastDate instanceof \DateTime) {
403
            $this->dateOverride = new DateOverride(DateOverride::OPT_DATE_OVERRIDE, $pastDate);
404
        }
405
    }
406
}
407