Test Failed
Pull Request — master (#170)
by
unknown
07:39
created

MasterPricerExpertSearch::loadOptions()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 56

Duplication

Lines 21
Ratio 37.5 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 21
loc 56
ccs 0
cts 38
cp 0
rs 8.3377
c 0
b 0
f 0
cc 6
nc 32
nop 1
crap 42

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\MPFareFamily;
26
use Amadeus\Client\RequestOptions\Fare\MPItinerary;
27
use Amadeus\Client\RequestOptions\FareMasterPricerCalendarOptions;
28
use Amadeus\Client\RequestOptions\FareMasterPricerExSearch;
29
use Amadeus\Client\RequestOptions\TicketAtcShopperMpTbSearchOptions;
30
use Amadeus\Client\Struct\Fare\MasterPricer;
31
32
/**
33
 * Fare_MasterPricerExpertSearch message structure
34
 *
35
 * @package Amadeus\Client\Struct\Fare
36
 * @author Dieter Devlieghere <[email protected]>
37
 */
38
class MasterPricerExpertSearch extends BaseMasterPricerMessage
39
{
40
41
    /**
42
     * @var mixed
43
     */
44
    public $globalOptions;
45
    /**
46
     * @var MasterPricer\CustomerRef
47
     */
48
    public $customerRef;
49
    /**
50
     * @var mixed
51
     */
52
    public $formOfPaymentByPassenger;
53
    /**
54
     * @var mixed
55
     */
56
    public $solutionFamily;
57
    /**
58
     * @var mixed[]
59
     */
60
    public $passengerInfoGrp = [];
61
    /**
62
     * @var MasterPricer\FareFamilies[]
63
     */
64
    public $fareFamilies = [];
65
    /**
66
     * @var MasterPricer\PriceToBeat
67
     */
68
    public $priceToBeat;
69
    /**
70
     * @var mixed
71
     */
72
    public $taxInfo;
73
    /**
74
     * @var MasterPricer\TravelFlightInfo
75
     */
76
    public $travelFlightInfo;
77
    /**
78
     * @var array
79
     */
80
    public $valueSearch = [];
81
    /**
82
     * Itinerary
83
     *
84
     * @var MasterPricer\Itinerary[]
85
     */
86
    public $itinerary = [];
87
    /**
88
     * @var mixed
89
     */
90
    public $ticketChangeInfo;
91
    /**
92
     * @var mixed
93
     */
94
    public $combinationFareFamilies;
95
    /**
96
     * @var MasterPricer\FeeOption[]
97
     */
98
    public $feeOption;
99
    /**
100
     * @var MasterPricer\OfficeIdDetails[]
101
     */
102
    public $officeIdDetails;
103
104
    /**
105
     * MasterPricerExpertSearch constructor.
106
     *
107
     * @param FareMasterPricerExSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpExSearchOptions|null $options
108
     */
109
    public function __construct($options = null)
110
    {
111
        if ($options instanceof FareMasterPricerExSearch) {
0 ignored issues
show
Bug introduced by
The class Amadeus\Client\RequestOp...areMasterPricerExSearch does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
112
            $this->loadOptions($options);
113
        }
114
    }
115
116
    /**
117
     * @param FareMasterPricerExSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpExSearchOptions $options
118
     */
119
    protected function loadOptions($options)
120
    {
121
        $this->loadNumberOfUnits($options);
122
123
        $this->loadFareOptions($options);
124
125
        $passengerCounter = 1;
126
        $infantCounter = 1;
127
        foreach ($options->passengers as $passenger) {
128
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
129
        }
130
131
        $segmentCounter = 1;
132
        foreach ($options->itinerary as $itinerary) {
133
            $this->loadItinerary($itinerary, $segmentCounter);
134
        }
135
136
        foreach ($options->officeIds as $officeId) {
137
            $this->loadOfficeId($officeId);
138
        }
139
140 View Code Duplication
        if ($this->checkAnyNotEmpty(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
141
            $options->cabinClass,
142
            $options->cabinOption,
143
            $options->requestedFlightTypes,
144
            $options->airlineOptions,
145
            $options->progressiveLegsMin,
146
            $options->progressiveLegsMax,
147
            $options->maxLayoverPerConnectionHours,
148
            $options->maxLayoverPerConnectionMinutes
149
        )) {
150
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
151
            $options->cabinClass,
152
            $options->cabinOption,
153
            $options->requestedFlightTypes,
154
            $options->airlineOptions,
155
            $options->progressiveLegsMin,
156
            $options->progressiveLegsMax,
157
            $options->maxLayoverPerConnectionHours,
158
            $options->maxLayoverPerConnectionMinutes
159
        );
160
        }
161
162
        if (!empty($options->priceToBeat)) {
163
            $this->priceToBeat = new MasterPricer\PriceToBeat(
164
                $options->priceToBeat,
165
                $options->priceToBeatCurrency
166
            );
167
        }
168
169
        $this->loadFareFamilies($options->fareFamilies);
170
171
        $this->loadCustomerRefs($options->dkNumber);
172
173
        $this->loadFeeOptions($options->feeOption);
174
    }
175
176
    /**
177
     * @param string $officeId
178
     */
179
    protected function loadOfficeId($officeId)
180
    {
181
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
182
    }
183
184
    /**
185
     * @param MPItinerary $opt
186
     * @param int $counter BYREF
187
     */
188
    protected function loadItinerary($opt, &$counter)
189
    {
190
        $segmentRef = $counter;
191
192
        if (!empty($opt->segmentReference)) {
193
            $segmentRef = $opt->segmentReference;
194
        }
195
196
        $tmpItinerary = new MasterPricer\Itinerary($segmentRef);
197
198
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
199
            $opt->departureLocation
200
        );
201
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
202
            $opt->arrivalLocation
203
        );
204
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($opt->date);
205
206 View Code Duplication
        if ($this->checkAnyNotEmpty(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
207
            $opt->airlineOptions,
208
            $opt->requestedFlightTypes,
209
            $opt->includedConnections,
210
            $opt->excludedConnections,
211
            $opt->nrOfConnections,
212
            $opt->cabinClass,
213
            $opt->cabinOption
214
        )) {
215
            $tmpItinerary->flightInfo = new MasterPricer\FlightInfo(
216
                $opt->airlineOptions,
217
                $opt->requestedFlightTypes,
218
                $opt->includedConnections,
219
                $opt->excludedConnections,
220
                $opt->nrOfConnections,
221
                null,
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a boolean.

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...
222
                $opt->cabinClass,
223
                $opt->cabinOption
224
            );
225
        }
226
227
        $this->itinerary[] = $tmpItinerary;
228
229
        $counter++;
230
    }
231
232
    /**
233
     * @param MPFareFamily[] $fareFamilies
234
     */
235
    protected function loadFareFamilies($fareFamilies)
236
    {
237
        foreach ($fareFamilies as $fareFamily) {
238
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
239
        }
240
    }
241
242
    /**
243
     * Load Customer references
244
     *
245
     * @param string $dkNumber
246
     */
247 View Code Duplication
    protected function loadCustomerRefs($dkNumber)
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...
248
    {
249
        if (!is_null($dkNumber)) {
250
            $this->customerRef = new MasterPricer\CustomerRef();
251
            $this->customerRef->customerReferences[] = new MasterPricer\CustomerReferences(
252
                $dkNumber,
253
                MasterPricer\CustomerReferences::QUAL_AGENCY_GROUPING_ID
254
            );
255
        }
256
    }
257
258
    private function loadFeeOptions($feeOptions)
259
    {
260
        if (!is_null($feeOptions)) {
261
            foreach ($feeOptions as $feeOption) {
262
                $this->feeOption[] = new MasterPricer\FeeOption($feeOption);
263
            }
264
        }
265
    }
266
}
267