Completed
Pull Request — master (#248)
by
unknown
32:06
created

checkUnsupportedOptions()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 9.3554
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5.025
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 92
    public function __construct($options)
124
    {
125 92
        $this->overrideInformation = new OverrideInformation();
126
127 92
        if (!is_null($options)) {
128 92
            $this->loadPricingOptions($options);
129 40
        }
130 80
    }
131
132
    /**
133
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
134
     */
135 92
    protected function loadPricingOptions($options)
136
    {
137 92
        $this->checkUnsupportedOptions($options);
138
139 80
        $this->loadOverrideOptionsAndCorpFares($options);
140
141 80
        $this->loadCurrencyOverride($options->currencyOverride);
142
143 80
        $this->loadValidatingCarrier($options);
144
145 80
        $this->loadFareBasis($options);
146
147 80
        $this->loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs);
148
149 80
        $this->loadOverrideLocations($options);
150
151 80
        $this->loadTaxOptions($options);
152
153 80
        $this->loadReferences($options->references);
154
155 80
        $this->loadPastDate($options->pastDatePricing);
156 80
    }
157
158
    /**
159
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
160
     * @throws OptionNotSupportedException
161
     */
162 92
    protected function checkUnsupportedOptions($options)
163
    {
164 92
        if (!empty($options->obFees)) {
165 4
            throw new OptionNotSupportedException('OB Fees option not supported in version 12 or lower');
166
        }
167
168 88
        if (!empty($options->pricingLogic)) {
169 4
            throw new OptionNotSupportedException('Pricing Logic option not supported in version 12 or lower');
170
        }
171
172 84
        if (!empty($options->overrideOptionsWithCriteria)) {
173 4
            throw new OptionNotSupportedException('Override Options With Criteria are not supported in version 12 or lower');
174
        }
175
176 80
        if (!empty($options->cabin)) {
177
            throw new OptionNotSupportedException('Cabin option is not supported in version 12 or lower');
178
        }
179 80
    }
180
181
    /**
182
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
183
     */
184 80
    protected function loadOverrideOptionsAndCorpFares($options)
185
    {
186 80
        foreach ($options->overrideOptions as $overrideOption) {
187 20
            $this->overrideInformation->attributeDetails[] = new AttributeDetails($overrideOption);
188 40
        }
189
190 80
        if (!empty($options->ticketType)) {
191 4
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
192 4
                $this->convertTicketType($options->ticketType)
193 2
            );
194 2
        }
195
196 80
        if ($options->corporateNegoFare !== null) {
197 4
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
198 4
                AttributeDetails::OVERRIDE_FARETYPE_CORPNR,
199 4
                $options->corporateNegoFare
200 2
            );
201 2
        }
202
203 80
        if (!empty($options->corporateUniFares)) {
204 8
            $this->loadCorporateUniFares($options->corporateUniFares);
205
206 8
            if (!empty($options->awardPricing)) {
207 4
                $this->carrierAgreements = new CarrierAgreements($options->awardPricing->carrier);
208 4
                $this->frequentFlyerInformation = new FrequentFlyerInformation($options->awardPricing->tierLevel);
209 2
            }
210 4
        }
211
212
        //No Options?
213 80
        if (empty($this->overrideInformation->attributeDetails)) {
214 44
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
215 22
                AttributeDetails::OVERRIDE_NO_OPTION
216 22
            );
217 22
        }
218 80
    }
219
220
    /**
221
     * @param string|null $currencyOverride
222
     */
223 80
    protected function loadCurrencyOverride($currencyOverride)
224
    {
225 80
        if (!empty($currencyOverride)) {
226 16
            $this->currencyOverride = new CurrencyOverride($currencyOverride);
227 8
        }
228 80
    }
229
230
    /**
231
     * Convert new codes (Price PNR version 13+) to old format
232
     *
233
     * @param string $optionsTicketType
234
     * @return string|null
235
     */
236 4
    protected function convertTicketType($optionsTicketType)
237
    {
238 4
        $converted = null;
239
240
        $map = [
241 4
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_ELECTRONIC => AttributeDetails::OVERRIDE_ELECTRONIC_TICKET,
242 4
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_PAPER => AttributeDetails::OVERRIDE_PAPER_TICKET,
243 4
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_BOTH => AttributeDetails::OVERRIDE_BOTH_TICKET,
244 2
        ];
245
246 4
        if (array_key_exists($optionsTicketType, $map)) {
247 4
            $converted = $map[$optionsTicketType];
248 2
        }
249
250 4
        return $converted;
251
    }
252
253
    /**
254
     * @param string[] $corporateUniFares
255
     */
256 8
    protected function loadCorporateUniFares($corporateUniFares)
257
    {
258 8
        foreach ($corporateUniFares as $corporateUniFare) {
259 8
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
260 8
                AttributeDetails::OVERRIDE_FARETYPE_CORPUNI,
261 4
                $corporateUniFare
262 4
            );
263 4
        }
264 8
    }
265
266
    /**
267
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
268
     */
269 80
    protected function loadOverrideLocations($options)
270
    {
271 80
        if (!empty($options->pointOfSaleOverride)) {
272 4
            $this->cityOverride = new PricePnr12\CityOverride(
273 4
                $options->pointOfSaleOverride,
274 2
                CityDetail::QUAL_POINT_OF_SALE
275 2
            );
276 2
        }
277
278 80
        if (!empty($options->pointOfTicketingOverride)) {
279 8
            if (empty($this->cityOverride)) {
280 4
                $this->cityOverride = new PricePnr12\CityOverride();
281 2
            }
282 8
            $this->cityOverride->cityDetail[] = new PricePnr12\CityDetail(
283 8
                $options->pointOfTicketingOverride,
284 4
                CityDetail::QUAL_POINT_OF_TICKETING
285 4
            );
286 4
        }
287 80
    }
288
289
    /**
290
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
291
     */
292 80
    protected function loadValidatingCarrier($options)
293
    {
294 80
        if (is_string($options->validatingCarrier)) {
295 20
            $this->validatingCarrier = new ValidatingCarrier($options->validatingCarrier);
296 10
        }
297 80
    }
298
299
    /**
300
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
301
     *
302
     */
303 80
    protected function loadFareBasis($options)
304
    {
305 80
        $short = AttributeDetails::OVERRIDE_FAREBASIS; //Short var name because I get complaints from phpcs. No judging.
306 80
        if (in_array($short, $options->overrideOptions) && !empty($options->pricingsFareBasis)) {
307 8
            foreach ($options->pricingsFareBasis as $pricingFareBasis) {
308 8
                $this->pricingFareBase[] = new PricingFareBase($pricingFareBasis);
309 4
            }
310 4
        }
311 80
    }
312
313
    /**
314
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
315
     */
316 80
    protected function loadTaxOptions($options)
317
    {
318 80
        foreach ($options->taxes as $tax) {
319 4
            $this->taxDetails[] = new TaxDetails($tax);
320 40
        }
321
322 80
        foreach ($options->exemptTaxes as $exemptTax) {
323 4
            $this->taxDetails[] = new TaxDetails($exemptTax);
324 40
        }
325 80
    }
326
327
    /**
328
     * @param string[] $paxDiscountCodes
329
     * @param PaxSegRef[] $refs
330
     */
331 80
    protected function loadPaxDiscount($paxDiscountCodes, $refs)
332
    {
333 80
        if (!empty($paxDiscountCodes)) {
334 12
            $this->discountInformation[] = new DiscountInformation(
335 12
                PenDisInformation::QUAL_DISCOUNT,
336 12
                $paxDiscountCodes,
337 6
                $refs
338 6
            );
339 6
        }
340 80
    }
341
342
    /**
343
     * @param PaxSegRef[] $references
344
     */
345 80
    protected function loadReferences($references)
346
    {
347 80
        if (!empty($references)) {
348 4
            $this->paxSegReference = new PricePnr12\PaxSegReference($references);
349 2
        }
350 80
    }
351
352
    /**
353
     * @param \DateTime|null $pastDate
354
     */
355 80
    protected function loadPastDate($pastDate)
356
    {
357 80
        if ($pastDate instanceof \DateTime) {
358 4
            $this->dateOverride = new DateOverride(DateOverride::OPT_DATE_OVERRIDE, $pastDate);
359 2
        }
360 80
    }
361
}
362