Completed
Push — master ( 34b639...00cc71 )
by Dieter
05:14
created

MasterPricerTravelBoardSearch::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 3
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 mixed
121
     */
122
    public $officeIdDetails;
123
124
    /**
125
     * MasterPricerTravelBoardSearch constructor.
126
     *
127
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|null $options
128
     */
129 21
    public function __construct($options = null)
130
    {
131 21
        if ($options instanceof FareMasterPricerTbSearch || $options instanceof FareMasterPricerCalendarOptions) {
132 21
            $this->loadOptions($options);
133 21
        }
134 21
    }
135
136
    /**
137
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions $options
138
     */
139 21
    protected function loadOptions($options)
140
    {
141 21
        $this->loadNrOfPaxAndResults($options);
142
143 21
        if ($options->doTicketabilityPreCheck === true ||
144 20
            $this->checkAnyNotEmpty($options->corporateCodesUnifares, $options->flightOptions)
145 21
        ) {
146 3
            $this->fareOptions = new MasterPricer\FareOptions(
147 3
                $options->flightOptions,
148 3
                $options->corporateCodesUnifares,
149 3
                $options->doTicketabilityPreCheck
150 3
            );
151 3
        }
152
153 21
        $passengerCounter = 1;
154 21
        $infantCounter = 1;
155 21
        foreach ($options->passengers as $passenger) {
156 20
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
157 21
        }
158
159 21
        $segmentCounter = 1;
160 21
        foreach ($options->itinerary as $itinerary) {
161 20
            $this->loadItinerary($itinerary, $segmentCounter);
162 21
        }
163
164 21
        if ($this->checkAnyNotEmpty(
165 21
            $options->cabinClass,
166 21
            $options->cabinOption,
167 21
            $options->requestedFlightTypes,
168 21
            $options->airlineOptions
169 21
        )) {
170 6
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
171 6
                $options->cabinClass,
172 6
                $options->cabinOption,
173 6
                $options->requestedFlightTypes,
174 6
                $options->airlineOptions
175 6
            );
176 6
        }
177
178 21
        if (!empty($options->priceToBeat)) {
179 1
            $this->priceToBeat = new MasterPricer\PriceToBeat(
180 1
                $options->priceToBeat,
181 1
                $options->priceToBeatCurrency
182 1
            );
183 1
        }
184
185 21
        $this->loadFareFamilies($options->fareFamilies);
186 21
    }
187
188
    /**
189
     * @param MPPassenger $passenger
190
     * @param int $counter BYREF
191
     * @param int $infantCounter BYREF
192
     */
193 20
    protected function loadPassenger($passenger, &$counter, &$infantCounter)
194
    {
195 20
        $isInfant = ($passenger->type === 'INF');
196
197 20
        $paxRef = new MasterPricer\PaxReference(
198 20
            $isInfant ? $infantCounter : $counter,
199 20
            $isInfant,
200 20
            $passenger->type
201 20
        );
202
203 20
        if ($isInfant) {
204 1
            $infantCounter++;
205 1
        } else {
206 20
            $counter++;
207
        }
208
209 20
        if ($passenger->count > 1) {
210 2
            for ($i = 2; $i <= $passenger->count; $i++) {
211 2
                $tmpCount = ($isInfant) ? $infantCounter : $counter;
212 2
                $paxRef->traveller[] = new MasterPricer\Traveller($tmpCount, $isInfant);
213
214 2
                if ($isInfant) {
215 1
                    $infantCounter++;
216 1
                } else {
217 2
                    $counter++;
218
                }
219 2
            }
220 2
        }
221
222 20
        $this->paxReference[] = $paxRef;
223 20
    }
224
225
    /**
226
     * @param MPItinerary $itineraryOptions
227
     * @param int $counter BYREF
228
     */
229 20
    protected function loadItinerary($itineraryOptions, &$counter)
230
    {
231 20
        $tmpItinerary = new MasterPricer\Itinerary($counter);
232
233 20
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
234 20
            $itineraryOptions->departureLocation
235 20
        );
236 20
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
237 20
            $itineraryOptions->arrivalLocation
238 20
        );
239 20
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($itineraryOptions->date);
240
241 20
        $this->itinerary[] = $tmpItinerary;
242
243 20
        $counter++;
244 20
    }
245
246
    /**
247
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions $options
248
     * @return void
249
     */
250 21
    protected function loadNrOfPaxAndResults(FareMasterPricerTbSearch $options)
251
    {
252 21
        if (is_int($options->nrOfRequestedPassengers) || is_int($options->nrOfRequestedResults)) {
253 20
            $this->numberOfUnit = new MasterPricer\NumberOfUnit(
254 20
                $options->nrOfRequestedPassengers,
255 20
                $options->nrOfRequestedResults
256 20
            );
257 20
        }
258 21
    }
259
260
    /**
261
     * @param MPFareFamily[] $fareFamilies
262
     */
263 21
    protected function loadFareFamilies($fareFamilies)
264
    {
265 21
        foreach ($fareFamilies as $fareFamily) {
266 2
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
267 21
        }
268 21
    }
269
}
270