Completed
Pull Request — master (#220)
by
unknown
18:24 queued 07:44
created

makePricingOptionForValidatingCarrier()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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 32
        }
69 64
    }
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...
82 32
        );
83
        
84 64
        $priceOptions = self::mergeOptions(
85 64
            $priceOptions,
86 64
            self::makePricingOptionForValidatingCarrier($options->validatingCarrier)
87 32
        );
88
89 64
        $priceOptions = self::mergeOptions(
90 64
            $priceOptions,
91 64
            self::makePricingOptionForCurrencyOverride($options->currencyOverride)
92 32
        );
93
94 64
        $priceOptions = self::mergeOptions(
95 64
            $priceOptions,
96 64
            self::makePricingOptionWithOptionDetailAndRefs(
97 64
                PricingOptionKey::OVERRIDE_ACCOUNT_CODE,
98 64
                $options->accountCode,
99 64
                $options->accountCodeRefs
100 32
            )
101 32
        );
102
103 64
        $priceOptions = self::mergeOptions(
104 64
            $priceOptions,
105 64
            self::makePricingOptionWithOptionDetailAndRefs(
106 64
                PricingOptionKey::OVERRIDE_AWARD,
107 64
                $options->awardPricing,
108 64
                []
109 32
            )
110 32
        );
111
112 64
        $priceOptions = self::mergeOptions(
113 64
            $priceOptions,
114 64
            self::makePricingOptionWithOptionDetailAndRefs(
115 64
                PricingOptionKey::OVERRIDE_CORPORATION_NUMBER,
116 64
                $options->corporationNumber,
117 64
                []
118 32
            )
119 32
        );
120
121 64
        $priceOptions = self::mergeOptions(
122 64
            $priceOptions,
123 64
            self::loadDateOverride($options->overrideDate)
124 32
        );
125
126 64
        $priceOptions = self::mergeOptions(
127 64
            $priceOptions,
128 64
            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 64
        $priceOptions = self::mergeOptions($priceOptions, self::loadPointOverrides($options->pointOfSaleOverride));
131
        
132 64
        $priceOptions = self::mergeOptions($priceOptions, self::loadFormOfPaymentOverride($options->formOfPayment));
133
        
134 64
        $priceOptions = self::mergeOptions($priceOptions, self::loadFrequentFlyerOverride($options->frequentFlyers));
135
        
136 64
        $priceOptions = self::mergeOptions($priceOptions, self::loadReferences($options->references));
137
        
138 64
        $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 32
        );
140
141
        // All options processed, no options found:
142 64
        if (empty($priceOptions)) {
143 12
            $priceOptions[] = new PricingOption(PricingOptionKey::OVERRIDE_NO_OPTION);
144 6
        }
145
146 64
        return $priceOptions;
147
    }
148
149
    /**
150
     *
151
     * @param FareBasis[] $pricingsFareBasis
152
     * @return PricingOptionGroup[]
153
     */
154 64 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 64
        $opt = [];
157 64
        if ($pricingsFareBasis !== null) {
158 64
            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 32
            }
167 32
        }
168
        
169 64
        return $opt;
170
    }
171
    
172
173
    /**
174
     * @param string|null $validatingCarrier
175
     * @return PricingOption[]
176
     */
177 64 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 64
        $opt = [];
180
181 64
        if ($validatingCarrier !== null) {
182 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_VALIDATING_CARRIER);
183
184 4
            $po->carrierInformation = new CarrierInformation($validatingCarrier);
185
186 4
            $opt[] = $po;
187 2
        }
188
189 64
        return $opt;
190
    }
191
192
    /**
193
     * @param string|null $currency
194
     * @return PricingOption[]
195
     */
196 64 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 64
        $opt = [];
199
200 64
        if ($currency !== null) {
201 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_CURRENCY);
202
203 4
            $po->currency = new Currency($currency);
204
205 4
            $opt[] = $po;
206 2
        }
207
208 64
        return $opt;
209
    }
210
211
    /**
212
     * @param string $overrideCode
213
     * @param string|array|null $options
214
     * @param PaxSegRef[] $references
215
     * @return PricingOption[]
216
     */
217 64
    protected static function makePricingOptionWithOptionDetailAndRefs($overrideCode, $options, $references)
218
    {
219 64
        $opt = [];
220
221 64
        if ($options !== null) {
222 20
            $po = new PricingOption($overrideCode);
223
224 20
            $po->optionDetail = new OptionDetail($options);
225
226 20
            if (!empty($references)) {
227 8
                $po->paxSegTstReference = new PaxSegTstReference($references);
228 4
            }
229
230 20
            $opt[] = $po;
231 10
        }
232
233 64
        return $opt;
234
    }
235
236
    /**
237
     * @param \DateTime|null $dateOverride
238
     * @return PricingOption[]
239
     */
240 64 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 64
        $opt = [];
243
244 64
        if ($dateOverride instanceof \DateTime) {
245 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PRICING_DATE);
246
247 4
            $po->dateInformation = new DateInformation(
248 4
                DateInformation::OPT_DATE_OVERRIDE,
249 2
                $dateOverride
250 2
            );
251
252 4
            $opt[] = $po;
253 2
        }
254
255 64
        return $opt;
256
    }
257
258
    /**
259
     * @param string|null $posOverride
260
     * @return PricingOption[]
261
     */
262 64 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 64
        $opt = [];
265
266 64
        if (!empty($posOverride)) {
267 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_POINT_OF_SALE);
268
269 4
            $po->locationInformation = new LocationInformation(
270 4
                LocationInformation::TYPE_POINT_OF_SALE,
271 2
                $posOverride
272 2
            );
273
274 4
            $opt[] = $po;
275 2
        }
276
277 64
        return $opt;
278
    }
279
280
    /**
281
     * @param FormOfPayment[] $formOfPayment
282
     * @return PricingOption[]
283
     */
284 64 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 64
        $opt = [];
287
288 64
        if (!empty($formOfPayment)) {
289 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FORM_OF_PAYMENT);
290
291 4
            $po->formOfPaymentInformation = new FormOfPaymentInformation($formOfPayment);
292
293 4
            $opt[] = $po;
294 2
        }
295
296 64
        return $opt;
297
    }
298
299
    /**
300
     * @param FrequentFlyer[] $frequentFlyers
301
     * @return PricingOption[]
302
     */
303 64 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 64
        $opt = [];
306
307 64
        if (!empty($frequentFlyers)) {
308 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_FREQUENT_FLYER_INFORMATION);
309
310 4
            $po->frequentFlyerInformation = new FrequentFlyerInformation($frequentFlyers);
311
312 4
            $opt[] = $po;
313 2
        }
314
315 64
        return $opt;
316
    }
317
318
    /**
319
     * @param PaxSegRef[] $references
320
     * @return PricingOption[]
321
     */
322 64 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 64
        $opt = [];
325
326 64
        if (!empty($references)) {
327 4
            $po = new PricingOption(PricingOptionKey::OVERRIDE_PAX_SEG_ELEMENT_SELECTION);
328
329 4
            $po->paxSegTstReference = new PaxSegTstReference($references);
330
331 4
            $opt[] = $po;
332 2
        }
333
334 64
        return $opt;
335
    }
336
337
    /**
338
     * @param string[] $overrideOptions
339
     * @param PricingOption[] $priceOptions
340
     * @return PricingOption[]
341
     */
342 64 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 64
        $opt = [];
345
346 64
        foreach ($overrideOptions as $overrideOption) {
347 4
            if (!self::hasPricingGroup($overrideOption, $priceOptions)) {
348 4
                $opt[] = new PricingOption($overrideOption);
349 2
            }
350 32
        }
351
352 64
        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 64
    protected static function mergeOptions($existingOptions, $newOptions)
363
    {
364 64
        if (!empty($newOptions)) {
365 52
            $existingOptions = array_merge(
366 52
                $existingOptions,
367 26
                $newOptions
368 26
            );
369 26
        }
370
371 64
        return $existingOptions;
372
    }
373
}
374