Completed
Push — master ( 64cf33...a63b4c )
by Dieter
05:52
created

loadNrOfPaxAndResults()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
crap 3
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\Fare\MPPassenger;
28
use Amadeus\Client\RequestOptions\FareMasterPricerCalendarOptions;
29
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
30
use Amadeus\Client\Struct\BaseWsMessage;
31
use Amadeus\Client\Struct\Fare\MasterPricer;
32
33
/**
34
 * Fare_MasterPricerTravelBoardSearch message structure
35
 *
36
 * @package Amadeus\Client\Struct\Fare
37
 * @author Dieter Devlieghere <[email protected]>
38
 */
39
class MasterPricerTravelBoardSearch extends BaseWsMessage
40
{
41
    /**
42
     * Number of seats, recommendations.
43
     *
44
     * @var MasterPricer\NumberOfUnit
45
     */
46
    public $numberOfUnit;
47
    /**
48
     * @var mixed
49
     */
50
    public $globalOptions;
51
    /**
52
     * Traveler Details
53
     *
54
     * @var MasterPricer\PaxReference[]
55
     */
56
    public $paxReference = [];
57
    /**
58
     * @var mixed
59
     */
60
    public $customerRef;
61
    /**
62
     * @var mixed
63
     */
64
    public $formOfPaymentByPassenger;
65
    /**
66
     * @var mixed
67
     */
68
    public $solutionFamily;
69
    /**
70
     * @var mixed[]
71
     */
72
    public $passengerInfoGrp = [];
73
    /**
74
     * @var MasterPricer\FareFamilies[]
75
     */
76
    public $fareFamilies = [];
77
    /**
78
     * @var MasterPricer\FareOptions
79
     */
80
    public $fareOptions;
81
    /**
82
     * @var MasterPricer\PriceToBeat
83
     */
84
    public $priceToBeat;
85
    /**
86
     * @var mixed
87
     */
88
    public $taxInfo;
89
    /**
90
     * @var MasterPricer\TravelFlightInfo
91
     */
92
    public $travelFlightInfo;
93
    /**
94
     * @var array
95
     */
96
    public $valueSearch = [];
97
    /**
98
     * @var array
99
     */
100
    public $buckets = [];
101
    /**
102
     * Itinerary
103
     *
104
     * @var MasterPricer\Itinerary[]
105
     */
106
    public $itinerary = [];
107
    /**
108
     * @var mixed
109
     */
110
    public $ticketChangeInfo;
111
    /**
112
     * @var mixed
113
     */
114
    public $combinationFareFamilies;
115
    /**
116
     * @var mixed
117
     */
118
    public $feeOption;
119
    /**
120
     * @var MasterPricer\OfficeIdDetails[]
121
     */
122
    public $officeIdDetails;
123
124
    /**
125
     * MasterPricerTravelBoardSearch constructor.
126
     *
127
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|null $options
128
     */
129 24
    public function __construct($options = null)
130
    {
131 24
        if ($options instanceof FareMasterPricerTbSearch || $options instanceof FareMasterPricerCalendarOptions) {
132 24
            $this->loadOptions($options);
133 24
        }
134 24
    }
135
136
    /**
137
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions $options
138
     */
139 24
    protected function loadOptions($options)
140
    {
141 24
        $this->loadNrOfPaxAndResults($options);
142
143 24
        if ($options->doTicketabilityPreCheck === true ||
144 23
            $this->checkAnyNotEmpty($options->corporateCodesUnifares, $options->flightOptions, $options->currencyOverride, $options->feeIds)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 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...
145 24
        ) {
146 6
            $this->fareOptions = new MasterPricer\FareOptions(
147 6
                $options->flightOptions,
148 6
                $options->corporateCodesUnifares,
149 6
                $options->doTicketabilityPreCheck,
150 6
                $options->currencyOverride,
151 6
                $options->feeIds,
152 6
                $options->corporateQualifier
153 6
            );
154 6
        }
155
156 24
        $passengerCounter = 1;
157 24
        $infantCounter = 1;
158 24
        foreach ($options->passengers as $passenger) {
159 23
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
160 24
        }
161
162 24
        $segmentCounter = 1;
163 24
        foreach ($options->itinerary as $itinerary) {
164 23
            $this->loadItinerary($itinerary, $segmentCounter);
165 24
        }
166
167 24
        foreach ($options->officeIds as $officeId) {
168 1
            $this->loadOfficeId($officeId);
169 24
        }
170
171 24
        if ($this->checkAnyNotEmpty(
172 24
            $options->cabinClass,
173 24
            $options->cabinOption,
174 24
            $options->requestedFlightTypes,
175 24
            $options->airlineOptions
176 24
        )) {
177 6
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
178 6
                $options->cabinClass,
179 6
                $options->cabinOption,
180 6
                $options->requestedFlightTypes,
181 6
                $options->airlineOptions
182 6
            );
183 6
        }
184
185 24
        if (!empty($options->priceToBeat)) {
186 1
            $this->priceToBeat = new MasterPricer\PriceToBeat(
187 1
                $options->priceToBeat,
188 1
                $options->priceToBeatCurrency
189 1
            );
190 1
        }
191
192 24
        $this->loadFareFamilies($options->fareFamilies);
193 24
    }
194
195
    /**
196
     * @param string $officeId
197
     */
198 1
    protected function loadOfficeId($officeId)
199
    {
200 1
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
201 1
    }
202
203
    /**
204
     * @param MPPassenger $passenger
205
     * @param int $counter BYREF
206
     * @param int $infantCounter BYREF
207
     */
208 23
    protected function loadPassenger($passenger, &$counter, &$infantCounter)
209
    {
210 23
        $isInfant = ($passenger->type === 'INF');
211
212 23
        $paxRef = new MasterPricer\PaxReference(
213 23
            $isInfant ? $infantCounter : $counter,
214 23
            $isInfant,
215 23
            $passenger->type
216 23
        );
217
218 23
        if ($isInfant) {
219 1
            $infantCounter++;
220 1
        } else {
221 23
            $counter++;
222
        }
223
224 23
        if ($passenger->count > 1) {
225 2
            for ($i = 2; $i <= $passenger->count; $i++) {
226 2
                $tmpCount = ($isInfant) ? $infantCounter : $counter;
227 2
                $paxRef->traveller[] = new MasterPricer\Traveller($tmpCount, $isInfant);
228
229 2
                if ($isInfant) {
230 1
                    $infantCounter++;
231 1
                } else {
232 2
                    $counter++;
233
                }
234 2
            }
235 2
        }
236
237 23
        $this->paxReference[] = $paxRef;
238 23
    }
239
240
    /**
241
     * @param MPItinerary $itineraryOptions
242
     * @param int $counter BYREF
243
     */
244 23
    protected function loadItinerary($itineraryOptions, &$counter)
245
    {
246 23
        $tmpItinerary = new MasterPricer\Itinerary($counter);
247
248 23
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
249 23
            $itineraryOptions->departureLocation
250 23
        );
251 23
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
252 23
            $itineraryOptions->arrivalLocation
253 23
        );
254 23
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($itineraryOptions->date);
255
256 23
        $this->itinerary[] = $tmpItinerary;
257
258 23
        $counter++;
259 23
    }
260
261
    /**
262
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions $options
263
     * @return void
264
     */
265 24
    protected function loadNrOfPaxAndResults(FareMasterPricerTbSearch $options)
266
    {
267 24
        if (is_int($options->nrOfRequestedPassengers) || is_int($options->nrOfRequestedResults)) {
268 23
            $this->numberOfUnit = new MasterPricer\NumberOfUnit(
269 23
                $options->nrOfRequestedPassengers,
270 23
                $options->nrOfRequestedResults
271 23
            );
272 23
        }
273 24
    }
274
275
    /**
276
     * @param MPFareFamily[] $fareFamilies
277
     */
278 24
    protected function loadFareFamilies($fareFamilies)
279
    {
280 24
        foreach ($fareFamilies as $fareFamily) {
281 2
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
282 24
        }
283 24
    }
284
}
285