checkUnsupportedOptions()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

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