MasterPricerExpertSearch::loadOptions()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 55
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 44
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 55
rs 8.7217
ccs 44
cts 44
cp 1
cc 6
nc 32
nop 1
crap 6

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