Completed
Pull Request — master (#220)
by
unknown
10:08
created

IntegratedPricing::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.2559
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\RequestOptions\ServiceStandaloneCatalogueOptions;
31
use Amadeus\Client\Struct\Fare\BasePricingMessage;
32
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
33
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
34
use Amadeus\Client\Struct\Fare\PricePnr13\DateInformation;
35
use Amadeus\Client\Struct\Fare\PricePnr13\FormOfPaymentInformation;
36
use Amadeus\Client\Struct\Fare\PricePnr13\FrequentFlyerInformation;
37
use Amadeus\Client\Struct\Fare\PricePnr13\LocationInformation;
38
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
39
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
40
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
41
use Amadeus\Client\Struct\Service\IntegratedPricing\PricingOptionKey;
42
use Amadeus\Client\Struct\Service\IntegratedPricing\PricingOption;
43
44
/**
45
 * Service_IntegratedPricing request structure
46
 *
47
 * @package Amadeus\Client\Struct\Service
48
 * @author Dieter Devlieghere <[email protected]>
49
 */
50
class IntegratedPricing extends BasePricingMessage
51
{
52
53
    /**
54
     *
55
     * @var PricingOption[]
56
     */
57
    public $pricingOption = [];
58
        
59
    /**
60
     * IntegratedPricing constructor.
61
     *
62
     * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions|null $options
63
     */
64 64
    public function __construct($options = null)
65
    {
66 64
        if (!is_null($options)) {
67 64
            $this->pricingOption = $this->loadPricingOptions($options);
68
        }
69
    }
70
71
    /**
72
     * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions $options
73
     * @return PricingOption[]
74
     */
75 64
    public static function loadPricingOptions($options)
76
    {
77 64
        $priceOptions = [];
78
        
79 64
        $priceOptions = self::mergeOptions(
80 64
            $priceOptions,
81 64
            self::makePricingOptionFareBasisOverride($options->pricingsFareBasis)
0 ignored issues
show
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...
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...
82
        );
83
        
84
        $priceOptions = self::mergeOptions(
85
            $priceOptions,
86
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
87
        );
88
89
        $priceOptions = self::mergeOptions(
90
            $priceOptions,
91
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
92
        );
93
94
        $priceOptions = self::mergeOptions(
95
            $priceOptions,
96
            self::makePricingOptionWithOptionDetailAndRefs(
97
                PricingOptionKey::OVERRIDE_ACCOUNT_CODE,
98
                $options->accountCode,
99
                $options->accountCodeRefs
100
            )
101
        );
102
103
        $priceOptions = self::mergeOptions(
104
            $priceOptions,
105
            self::makePricingOptionWithOptionDetailAndRefs(
106
                PricingOptionKey::OVERRIDE_AWARD,
107
                $options->awardPricing,
108
                []
109
            )
110
        );
111
112
        $priceOptions = self::mergeOptions(
113
            $priceOptions,
114
            self::makePricingOptionWithOptionDetailAndRefs(
115
                PricingOptionKey::OVERRIDE_CORPORATION_NUMBER,
116
                $options->corporationNumber,
117
                []
118
            )
119
        );
120
121
        $priceOptions = self::mergeOptions(
122
            $priceOptions,
123
            self::loadDateOverride($options->overrideDate)
124
        );
125
126
        $priceOptions = self::mergeOptions(
127
            $priceOptions,
128
            self::makePricingOptionWithOptionDetailAndRefs(PricingOptionKey::OVERRIDE_TICKET_DESIGNATOR, $options->ticketDesignator, []));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 138 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
129
        
130
        $priceOptions = self::mergeOptions($priceOptions, self::loadPointOverrides($options->pointOfSaleOverride));
131
        
132
        $priceOptions = self::mergeOptions($priceOptions, self::loadFormOfPaymentOverride($options->formOfPayment));
133
        
134
        $priceOptions = self::mergeOptions($priceOptions, self::loadFrequentFlyerOverride($options->frequentFlyers));
135
        
136
        $priceOptions = self::mergeOptions($priceOptions, self::loadReferences($options->references));
137
        
138
        $priceOptions = self::mergeOptions($priceOptions, self::makeOverrideOptions($options->overrideOptions, $priceOptions)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
139
        );
140
141
        // All options processed, no options found:
142
        if (empty($priceOptions)) {
143
            $priceOptions[] = new PricingOption(PricingOptionKey::OVERRIDE_NO_OPTION);
144
        }
145
146
        return $priceOptions;
147
    }
148
149
    /**
150
     *
151
     * @param FareBasis[] $pricingsFareBasis
152
     * @return PricingOptionGroup[]
153
     */
154 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...
155
    {
156
        $opt = [];
157
        if ($pricingsFareBasis !== null) {
158
            foreach ($pricingsFareBasis as $pricingFareBasis) {
159
                $po = new PricingOptionGroup($pricingFareBasis->overrideType);
160
                
161
                $po->optionDetail = new OptionDetail($pricingFareBasis->fareBasisCode);
162
                
163
                $po->paxSegTstReference = new PaxSegTstReference($pricingFareBasis->references);
164
                
165
                $opt[] = $po;
166
            }
167
        }
168
        
169
        return $opt;
170
    }
171
    
172
173
    /**
174
     * @param string|null $validatingCarrier
175
     * @return PricingOption[]
176
     */
177 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...
178
    {
179
        $opt = [];
180
181
        if ($validatingCarrier !== null) {
182
            $po = new PricingOption(PricingOptionKey::OVERRIDE_VALIDATING_CARRIER);
183
184
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
185
186
            $opt[] = $po;
187
        }
188
189
        return $opt;
190
    }
191
192
    /**
193
     * @param string|null $currency
194
     * @return PricingOption[]
195
     */
196 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...
197
    {
198
        $opt = [];
199
200
        if ($currency !== null) {
201
            $po = new PricingOption(PricingOptionKey::OVERRIDE_CURRENCY);
202
203
            $po->currency = new Currency($currency);
204
205
            $opt[] = $po;
206
        }
207
208
        return $opt;
209
    }
210
211
    /**
212
     * @param string $overrideCode
213
     * @param string|array|null $options
214
     * @param PaxSegRef[] $references
215
     * @return PricingOption[]
216
     */
217
    protected static function makePricingOptionWithOptionDetailAndRefs($overrideCode, $options, $references)
218
    {
219
        $opt = [];
220
221
        if ($options !== null) {
222
            $po = new PricingOption($overrideCode);
223
224
            $po->optionDetail = new OptionDetail($options);
225
226
            if (!empty($references)) {
227
                $po->paxSegTstReference = new PaxSegTstReference($references);
228
            }
229
230
            $opt[] = $po;
231
        }
232
233
        return $opt;
234
    }
235
236
    /**
237
     * @param \DateTime|null $dateOverride
238
     * @return PricingOption[]
239
     */
240 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...
241
    {
242
        $opt = [];
243
244
        if ($dateOverride instanceof \DateTime) {
245
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PRICING_DATE);
246
247
            $po->dateInformation = new DateInformation(
248
                DateInformation::OPT_DATE_OVERRIDE,
249
                $dateOverride
250
            );
251
252
            $opt[] = $po;
253
        }
254
255
        return $opt;
256
    }
257
258
    /**
259
     * @param string|null $posOverride
260
     * @return PricingOption[]
261
     */
262 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...
263
    {
264
        $opt = [];
265
266
        if (!empty($posOverride)) {
267
            $po = new PricingOption(PricingOptionKey::OVERRIDE_POINT_OF_SALE);
268
269
            $po->locationInformation = new LocationInformation(
270
                LocationInformation::TYPE_POINT_OF_SALE,
271
                $posOverride
272
            );
273
274
            $opt[] = $po;
275
        }
276
277
        return $opt;
278
    }
279
280
    /**
281
     * @param FormOfPayment[] $formOfPayment
282
     * @return PricingOption[]
283
     */
284 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...
285
    {
286
        $opt = [];
287
288
        if (!empty($formOfPayment)) {
289
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FORM_OF_PAYMENT);
290
291
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
292
293
            $opt[] = $po;
294
        }
295
296
        return $opt;
297
    }
298
299
    /**
300
     * @param FrequentFlyer[] $frequentFlyers
301
     * @return PricingOption[]
302
     */
303 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...
304
    {
305
        $opt = [];
306
307
        if (!empty($frequentFlyers)) {
308
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FREQUENT_FLYER_INFORMATION);
309
310
            $po->frequentFlyerInformation = new FrequentFlyerInformation($frequentFlyers);
311
312
            $opt[] = $po;
313
        }
314
315
        return $opt;
316
    }
317
318
    /**
319
     * @param PaxSegRef[] $references
320
     * @return PricingOption[]
321
     */
322 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...
323
    {
324
        $opt = [];
325
326
        if (!empty($references)) {
327
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PAX_SEG_ELEMENT_SELECTION);
328
329
            $po->paxSegTstReference = new PaxSegTstReference($references);
330
331
            $opt[] = $po;
332
        }
333
334
        return $opt;
335
    }
336
337
    /**
338
     * @param string[] $overrideOptions
339
     * @param PricingOption[] $priceOptions
340
     * @return PricingOption[]
341
     */
342 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...
343
    {
344
        $opt = [];
345
346
        foreach ($overrideOptions as $overrideOption) {
347
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
348
                $opt[] = new PricingOption($overrideOption);
349
            }
350
        }
351
352
        return $opt;
353
    }
354
355
    /**
356
     * Merges Pricing options
357
     *
358
     * @param PricingOption[] $existingOptions
359
     * @param PricingOption[] $newOptions
360
     * @return PricingOption[] merged array
361
     */
362
    protected static function mergeOptions($existingOptions, $newOptions)
363
    {
364
        if (!empty($newOptions)) {
365
            $existingOptions = array_merge(
366
                $existingOptions,
367
                $newOptions
368
            );
369
        }
370
371
        return $existingOptions;
372
    }
373
}
374