Test Failed
Pull Request — master (#220)
by
unknown
11:33 queued 59s
created

IntegratedPricing   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 324
Duplicated Lines 41.05 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 5%

Importance

Changes 0
Metric Value
wmc 29
lcom 1
cbo 12
dl 133
loc 324
ccs 8
cts 160
cp 0.05
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
B loadPricingOptions() 0 73 2
A makePricingOptionFareBasisOverride() 17 17 3
A makePricingOptionForValidatingCarrier() 14 14 2
A makePricingOptionForCurrencyOverride() 14 14 2
A makePricingOptionWithOptionDetailAndRefs() 0 18 3
A loadDateOverride() 17 17 2
A loadPointOverrides() 17 17 2
A loadFormOfPaymentOverride() 14 14 2
A loadFrequentFlyerOverride() 14 14 2
A loadReferences() 14 14 2
A makeOverrideOptions() 12 12 3
A mergeOptions() 0 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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