Test Failed
Pull Request — master (#220)
by
unknown
08:55
created

IntegratedPricing::loadPointOverrides()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 11
cp 0
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\Service;
24
25
use Amadeus\Client\RequestOptions\Fare\PricePnr\PaxSegRef;
26
use Amadeus\Client\RequestOptions\Service\FormOfPayment;
27
use Amadeus\Client\RequestOptions\Service\FrequentFlyer;
28
use Amadeus\Client\RequestOptions\ServiceIntegratedCatalogueOptions;
29
use Amadeus\Client\RequestOptions\ServiceIntegratedPricingOptions;
30
use Amadeus\Client\Struct\Fare\BasePricingMessage;
31
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
32
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
33
use Amadeus\Client\Struct\Fare\PricePnr13\DateInformation;
34
use Amadeus\Client\Struct\Fare\PricePnr13\FormOfPaymentInformation;
35
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentFlyerInformation;
36
use Amadeus\Client\Struct\Fare\PricePnr13\LocationInformation;
37
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
38
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
39
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
40
use Amadeus\Client\Struct\Service\IntegratedPricing\PricingOptionKey;
41
use Amadeus\Client\Struct\Service\IntegratedPricing\PricingOption;
42
43
/**
44
 * Service_IntegratedPricing request structure
45
 *
46
 * @package Amadeus\Client\Struct\Service
47
 * @author Dieter Devlieghere <[email protected]>
48
 */
49
class IntegratedPricing extends BasePricingMessage
50
{
51
    /**
52
     * @var PricingOption[]
53
     */
54
    public $pricingOption = [];
55
56
    /**
57
     * IntegratedPricing constructor.
58
     *
59
     * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions|null $options
60
     */
61 64
    public function __construct($options = null)
62
    {
63 64
        if (!is_null($options)) {
64 64
            $this->pricingOption = $this->loadPricingOptions($options);
65
        }
66
    }
67
68
    /**
69
     * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions $options
70
     * @return PricingOption[]
71
     */
72 64
    public static function loadPricingOptions($options)
73
    {
74 64
        $priceOptions = [];
75
76 64
        $priceOptions = self::mergeOptions(
77 64
        		$priceOptions,
78 64
        		self::makePricingOptionFareBasisOverride($options->pricingsFareBasis)
0 ignored issues
show
Bug introduced by
The property pricingsFareBasis does not seem to exist in Amadeus\Client\RequestOp...ntegratedPricingOptions.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Documentation introduced by
self::makePricingOptionF...ons->pricingsFareBasis) is of type array<integer,object<Ama...13\PricingOptionGroup>>, but the function expects a array<integer,object<Ama...Pricing\PricingOption>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
        );
80
        
81
        $priceOptions = self::mergeOptions(
82
            $priceOptions,
83
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
84
        );
85
86
        $priceOptions = self::mergeOptions(
87
            $priceOptions,
88
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
89
        );
90
91
        $priceOptions = self::mergeOptions(
92
            $priceOptions,
93
            self::makePricingOptionWithOptionDetailAndRefs(
94
                PricingOptionKey::OVERRIDE_ACCOUNT_CODE,
95
                $options->accountCode,
96
                $options->accountCodeRefs
97
            )
98
        );
99
100
        $priceOptions = self::mergeOptions(
101
            $priceOptions,
102
            self::makePricingOptionWithOptionDetailAndRefs(
103
                PricingOptionKey::OVERRIDE_AWARD,
104
                $options->awardPricing,
105
                []
106
            )
107
        );
108
109
        $priceOptions = self::mergeOptions(
110
            $priceOptions,
111
            self::makePricingOptionWithOptionDetailAndRefs(
112
                PricingOptionKey::OVERRIDE_CORPORATION_NUMBER,
113
                $options->corporationNumber,
114
                []
115
            )
116
        );
117
118
        $priceOptions = self::mergeOptions(
119
            $priceOptions,
120
            self::loadDateOverride($options->overrideDate)
121
        );
122
123
        $priceOptions = self::mergeOptions(
124
            $priceOptions,
125
            self::makePricingOptionWithOptionDetailAndRefs(
126
                PricingOptionKey::OVERRIDE_TICKET_DESIGNATOR,
127
                $options->ticketDesignator,
128
                []
129
            )
130
        );
131
132
        $priceOptions = self::mergeOptions(
133
            $priceOptions,
134
            self::loadPointOverrides($options->pointOfSaleOverride)
135
        );
136
137
        $priceOptions = self::mergeOptions(
138
            $priceOptions,
139
            self::loadFormOfPaymentOverride($options->formOfPayment)
140
        );
141
142
        $priceOptions = self::mergeOptions(
143
            $priceOptions,
144
            self::loadFrequentFlyerOverride($options->frequentFlyers)
145
        );
146
147
        $priceOptions = self::mergeOptions(
148
            $priceOptions,
149
            self::loadReferences($options->references)
150
        );
151
152
        $priceOptions = self::mergeOptions(
153
            $priceOptions,
154
            self::makeOverrideOptions($options->overrideOptions, $priceOptions)
155
        );
156
157
        // All options processed, no options found:
158
        if (empty($priceOptions)) {
159
            $priceOptions[] = new PricingOption(PricingOptionKey::OVERRIDE_NO_OPTION);
160
        }
161
162
        return $priceOptions;
163
    }
164
    
165
    /**
166
     * @param FareBasis[] $pricingsFareBasis
167
     * @return PricingOptionGroup[]
168
     */
169 View Code Duplication
    protected static 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...
170
    {
171
    	$opt = [];
172
    
173
    	if ($pricingsFareBasis !== null) {
174
    		foreach ($pricingsFareBasis as $pricingFareBasis) {
175
    			$po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);
176
    
177
    			//Support for legacy fareBasisPrimaryCode to be removed when breaking BC:
178
    			$po->optionDetail = new OptionDetail(
179
    					$pricingFareBasis->fareBasisPrimaryCode.$pricingFareBasis->fareBasisCode
180
    			);
181
    
182
    			//Support for legacy segmentReference to be removed when breaking BC:
183
    			$po->paxSegTstReference = new PaxSegTstReference(
184
    					$pricingFareBasis->references,
185
    					$pricingFareBasis->segmentReference
186
    			);
187
    
188
    			$opt[] = $po;
189
    		}
190
    	}
191
    
192
    	return $opt;
193
    }
194
    
195
196
    /**
197
     * @param string|null $validatingCarrier
198
     * @return PricingOption[]
199
     */
200 View Code Duplication
    protected static function makePricingOptionForValidatingCarrier($validatingCarrier)
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...
201
    {
202
        $opt = [];
203
204
        if ($validatingCarrier !== null) {
205
            $po = new PricingOption(PricingOptionKey::OVERRIDE_VALIDATING_CARRIER);
206
207
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
208
209
            $opt[] = $po;
210
        }
211
212
        return $opt;
213
    }
214
215
    /**
216
     * @param string|null $currency
217
     * @return PricingOption[]
218
     */
219 View Code Duplication
    protected static 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...
220
    {
221
        $opt = [];
222
223
        if ($currency !== null) {
224
            $po = new PricingOption(PricingOptionKey::OVERRIDE_CURRENCY);
225
226
            $po->currency = new Currency($currency);
227
228
            $opt[] = $po;
229
        }
230
231
        return $opt;
232
    }
233
234
    /**
235
     * @param string $overrideCode
236
     * @param string|array|null $options
237
     * @param PaxSegRef[] $references
238
     * @return PricingOption[]
239
     */
240
    protected function makePricingOptionWithOptionDetailAndRefs($overrideCode, $options, $references)
241
    {
242
        $opt = [];
243
244
        if ($options !== null) {
245
            $po = new PricingOption($overrideCode);
246
247
            $po->optionDetail = new OptionDetail($options);
248
249
            if (!empty($references)) {
250
                $po->paxSegTstReference = new PaxSegTstReference($references);
251
            }
252
253
            $opt[] = $po;
254
        }
255
256
        return $opt;
257
    }
258
259
    /**
260
     * @param \DateTime|null $dateOverride
261
     * @return PricingOption[]
262
     */
263 View Code Duplication
    protected static function loadDateOverride($dateOverride)
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...
264
    {
265
        $opt = [];
266
267
        if ($dateOverride instanceof \DateTime) {
268
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PRICING_DATE);
269
270
            $po->dateInformation = new DateInformation(
271
                DateInformation::OPT_DATE_OVERRIDE,
272
                $dateOverride
273
            );
274
275
            $opt[] = $po;
276
        }
277
278
        return $opt;
279
    }
280
281
    /**
282
     * @param string|null $posOverride
283
     * @return PricingOption[]
284
     */
285 View Code Duplication
    protected static function loadPointOverrides($posOverride)
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...
286
    {
287
        $opt = [];
288
289
        if (!empty($posOverride)) {
290
            $po = new PricingOption(PricingOptionKey::OVERRIDE_POINT_OF_SALE);
291
292
            $po->locationInformation = new LocationInformation(
293
                LocationInformation::TYPE_POINT_OF_SALE,
294
                $posOverride
295
            );
296
297
            $opt[] = $po;
298
        }
299
300
        return $opt;
301
    }
302
303
    /**
304
     * @param FormOfPayment[] $formOfPayment
305
     * @return PricingOption[]
306
     */
307 View Code Duplication
    protected static function loadFormOfPaymentOverride($formOfPayment)
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...
308
    {
309
        $opt = [];
310
311
        if (!empty($formOfPayment)) {
312
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FORM_OF_PAYMENT);
313
314
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
315
316
            $opt[] = $po;
317
        }
318
319
        return $opt;
320
    }
321
322
    /**
323
     * @param FrequentFlyer[] $frequentFlyers
324
     * @return PricingOption[]
325
     */
326 View Code Duplication
    protected static function loadFrequentFlyerOverride($frequentFlyers)
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...
327
    {
328
        $opt = [];
329
330
        if (!empty($frequentFlyers)) {
331
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FREQUENT_FLYER_INFORMATION);
332
333
            $po->frequentFlyerInformation = new FrequentFlyerInformation($frequentFlyers);
334
335
            $opt[] = $po;
336
        }
337
338
        return $opt;
339
    }
340
341
    /**
342
     * @param PaxSegRef[] $references
343
     * @return PricingOption[]
344
     */
345 View Code Duplication
    protected static function loadReferences($references)
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...
346
    {
347
        $opt = [];
348
349
        if (!empty($references)) {
350
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PAX_SEG_ELEMENT_SELECTION);
351
352
            $po->paxSegTstReference = new PaxSegTstReference($references);
353
354
            $opt[] = $po;
355
        }
356
357
        return $opt;
358
    }
359
360
    /**
361
     * @param string[] $overrideOptions
362
     * @param PricingOption[] $priceOptions
363
     * @return PricingOption[]
364
     */
365 View Code Duplication
    protected static function makeOverrideOptions($overrideOptions, $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...
366
    {
367
        $opt = [];
368
369
        foreach ($overrideOptions as $overrideOption) {
370
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
371
                $opt[] = new PricingOption($overrideOption);
372
            }
373
        }
374
375
        return $opt;
376
    }
377
378
    /**
379
     * Merges Pricing options
380
     *
381
     * @param PricingOption[] $existingOptions
382
     * @param PricingOption[] $newOptions
383
     * @return PricingOption[] merged array
384
     */
385
    protected static function mergeOptions($existingOptions, $newOptions)
386
    {
387
        if (!empty($newOptions)) {
388
            $existingOptions = array_merge(
389
                $existingOptions,
390
                $newOptions
391
            );
392
        }
393
394
        return $existingOptions;
395
    }
396
}
397