MasterPricerTravelBoardSearch::loadOptions()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 8.2505
c 0
b 0
f 0
cc 6
nc 32
nop 1

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\MPTicketingPriceScheme;
26
use Amadeus\Client\RequestOptions\Fare\MPFareFamily;
27
use Amadeus\Client\RequestOptions\Fare\MPItinerary;
28
use Amadeus\Client\RequestOptions\FareMasterPricerCalendarOptions;
29
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
30
use Amadeus\Client\RequestOptions\TicketAtcShopperMpTbSearchOptions;
31
use Amadeus\Client\Struct\Fare\MasterPricer;
32
33
/**
34
 * Fare_MasterPricerTravelBoardSearch message structure
35
 *
36
 * Also used for Fare_MasterPricerCalendar and Ticket_ATCShopperMasterPricerTravelBoardSearch
37
 *
38
 * @package Amadeus\Client\Struct\Fare
39
 * @author Dieter Devlieghere <[email protected]>
40
 */
41
class MasterPricerTravelBoardSearch extends BaseMasterPricerMessage
42
{
43
    /**
44
     * @var mixed
45
     */
46
    public $globalOptions;
47
    /**
48
     * @var MasterPricer\CustomerRef
49
     */
50
    public $customerRef;
51
    /**
52
     * @var mixed
53
     */
54
    public $formOfPaymentByPassenger;
55
    /**
56
     * @var mixed
57
     */
58
    public $solutionFamily;
59
    /**
60
     * @var mixed[]
61
     */
62
    public $passengerInfoGrp = [];
63
    /**
64
     * @var MasterPricer\FareFamilies[]
65
     */
66
    public $fareFamilies = [];
67
    /**
68
     * @var MasterPricer\PriceToBeat
69
     */
70
    public $priceToBeat;
71
    /**
72
     * @var mixed
73
     */
74
    public $taxInfo;
75
    /**
76
     * @var MasterPricer\TravelFlightInfo
77
     */
78
    public $travelFlightInfo;
79
    /**
80
     * @var array
81
     */
82
    public $valueSearch = [];
83
    /**
84
     * Itinerary
85
     *
86
     * @var MasterPricer\Itinerary[]
87
     */
88
    public $itinerary = [];
89
    /**
90
     * @var MPTicketingPriceScheme
91
     */
92
    public $ticketingPriceScheme;
93
    /**
94
     * @var mixed
95
     */
96
    public $ticketChangeInfo;
97
    /**
98
     * @var mixed
99
     */
100
    public $combinationFareFamilies;
101
    /**
102
     * @var MasterPricer\FeeOption[]
103
     */
104
    public $feeOption;
105
    /**
106
     * @var MasterPricer\OfficeIdDetails[]
107
     */
108
    public $officeIdDetails;
109
110
    /**
111
     * MasterPricerTravelBoardSearch constructor.
112
     *
113
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpTbSearchOptions|null $options
114
     */
115
    public function __construct($options = null)
116
    {
117
        if ($options instanceof FareMasterPricerTbSearch) {
118
            $this->loadOptions($options);
119
        }
120
    }
121
122
    /**
123
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpTbSearchOptions $options
124
     */
125
    protected function loadOptions($options)
126
    {
127
        $this->loadNumberOfUnits($options);
128
129
        $this->loadFareOptions($options);
130
131
        $passengerCounter = 1;
132
        $infantCounter = 1;
133
        foreach ($options->passengers as $passenger) {
134
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
135
        }
136
137
        $segmentCounter = 1;
138
        foreach ($options->itinerary as $itinerary) {
139
            $this->loadItinerary($itinerary, $segmentCounter);
140
        }
141
142
        foreach ($options->officeIds as $officeId) {
143
            $this->loadOfficeId($officeId);
144
        }
145
146
        if ($this->checkAnyNotEmpty(
147
            $options->cabinClass,
148
            $options->cabinOption,
149
            $options->requestedFlightTypes,
150
            $options->airlineOptions,
151
            $options->progressiveLegsMin,
152
            $options->progressiveLegsMax,
153
            $options->maxLayoverPerConnectionHours,
154
            $options->maxLayoverPerConnectionMinutes,
155
            $options->noAirportChange,
156
            $options->maxElapsedFlyingTime
157
        )) {
158
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
159
                $options->cabinClass,
160
                $options->cabinOption,
161
                $options->requestedFlightTypes,
162
                $options->airlineOptions,
163
                $options->progressiveLegsMin,
164
                $options->progressiveLegsMax,
165
                $options->maxLayoverPerConnectionHours,
166
                $options->maxLayoverPerConnectionMinutes,
167
                $options->noAirportChange,
168
                $options->maxElapsedFlyingTime
169
            );
170
        }
171
172
        if (!is_null($options->priceToBeat)) {
173
            $this->priceToBeat = new MasterPricer\PriceToBeat(
174
                $options->priceToBeat,
175
                $options->priceToBeatCurrency
176
            );
177
        }
178
179
        $this->loadFareFamilies($options->fareFamilies);
180
181
        $this->loadCustomerRefs($options->dkNumber);
182
183
        $this->loadFeeOptions($options->feeOption);
184
    }
185
186
    /**
187
     * @param string $officeId
188
     */
189
    protected function loadOfficeId($officeId)
190
    {
191
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
192
    }
193
194
    /**
195
     * @param MPItinerary $opt
196
     * @param int $counter BYREF
197
     */
198
    protected function loadItinerary($opt, &$counter)
199
    {
200
        $segmentRef = $counter;
201
202
        if (!empty($opt->segmentReference)) {
203
            $segmentRef = $opt->segmentReference;
204
        }
205
206
        $tmpItinerary = new MasterPricer\Itinerary($segmentRef);
207
208
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
209
            $opt->departureLocation
210
        );
211
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
212
            $opt->arrivalLocation
213
        );
214
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($opt->date);
215
216 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...
217
            $opt->airlineOptions,
218
            $opt->requestedFlightTypes,
219
            $opt->includedConnections,
220
            $opt->excludedConnections,
221
            $opt->nrOfConnections,
222
            $opt->noAirportChange,
223
            $opt->cabinClass,
224
            $opt->cabinOption
225
        )) {
226
            $tmpItinerary->flightInfo = new MasterPricer\FlightInfo(
227
                $opt->airlineOptions,
228
                $opt->requestedFlightTypes,
229
                $opt->includedConnections,
230
                $opt->excludedConnections,
231
                $opt->nrOfConnections,
232
                $opt->noAirportChange,
233
                $opt->cabinClass,
234
                $opt->cabinOption
235
            );
236
        }
237
238
        $this->itinerary[] = $tmpItinerary;
239
240
        $counter++;
241
    }
242
243
    /**
244
     * @param MPFareFamily[] $fareFamilies
245
     */
246
    protected function loadFareFamilies($fareFamilies)
247
    {
248
        foreach ($fareFamilies as $fareFamily) {
249
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
250
        }
251
    }
252
253
    /**
254
     * Load Customer references
255
     *
256
     * @param string $dkNumber
257
     */
258 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...
259
    {
260
        if (!is_null($dkNumber)) {
261
            $this->customerRef = new MasterPricer\CustomerRef();
262
            $this->customerRef->customerReferences[] = new MasterPricer\CustomerReferences(
263
                $dkNumber,
264
                MasterPricer\CustomerReferences::QUAL_AGENCY_GROUPING_ID
265
            );
266
        }
267
    }
268
269
    private function loadFeeOptions($feeOptions)
270
    {
271
        if (!is_null($feeOptions)) {
272
            foreach ($feeOptions as $feeOption) {
273
                $this->feeOption[] = new MasterPricer\FeeOption($feeOption);
274
            }
275
        }
276
    }
277
}
278