Completed
Push — master ( 1ecee2...1e59ec )
by Dieter
07:27
created

MasterPricerTravelBoardSearch::loadOptions()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 46
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 46
rs 6.7272
c 1
b 0
f 0
cc 7
eloc 29
nc 32
nop 1
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\MPItinerary;
26
use Amadeus\Client\RequestOptions\Fare\MPPassenger;
27
use Amadeus\Client\RequestOptions\FareMasterPricerTbSearch;
28
use Amadeus\Client\Struct\BaseWsMessage;
29
use Amadeus\Client\Struct\Fare\MasterPricer;
30
31
/**
32
 * Fare_MasterPricerTravelBoardSearch message structure
33
 *
34
 * @package Amadeus\Client\Struct\Fare
35
 * @author Dieter Devlieghere <[email protected]>
36
 */
37
class MasterPricerTravelBoardSearch extends BaseWsMessage
38
{
39
    /**
40
     * Number of seats, recommendations.
41
     *
42
     * @var MasterPricer\NumberOfUnit
43
     */
44
    public $numberOfUnit;
45
    /**
46
     * @var mixed
47
     */
48
    public $globalOptions;
49
    /**
50
     * Traveler Details
51
     *
52
     * @var MasterPricer\PaxReference[]
53
     */
54
    public $paxReference = [];
55
    /**
56
     * @var mixed
57
     */
58
    public $customerRef;
59
    /**
60
     * @var mixed
61
     */
62
    public $formOfPaymentByPassenger;
63
    /**
64
     * @var mixed
65
     */
66
    public $solutionFamily;
67
    /**
68
     * @var mixed[]
69
     */
70
    public $passengerInfoGrp = [];
71
    /**
72
     * @var MasterPricer\FareFamilies[]
73
     */
74
    public $fareFamilies = [];
75
    /**
76
     * @var MasterPricer\FareOptions
77
     */
78
    public $fareOptions;
79
    /**
80
     * @var MasterPricer\PriceToBeat
81
     */
82
    public $priceToBeat;
83
    /**
84
     * @var mixed
85
     */
86
    public $taxInfo;
87
    /**
88
     * @var MasterPricer\TravelFlightInfo
89
     */
90
    public $travelFlightInfo;
91
    /**
92
     * @var array
93
     */
94
    public $valueSearch = [];
95
    /**
96
     * @var array
97
     */
98
    public $buckets = [];
99
    /**
100
     * Itinerary
101
     *
102
     * @var MasterPricer\Itinerary[]
103
     */
104
    public $itinerary = [];
105
    /**
106
     * @var mixed
107
     */
108
    public $ticketChangeInfo;
109
    /**
110
     * @var mixed
111
     */
112
    public $combinationFareFamilies;
113
    /**
114
     * @var mixed
115
     */
116
    public $feeOption;
117
    /**
118
     * @var mixed
119
     */
120
    public $officeIdDetails;
121
122
    /**
123
     * MasterPricerTravelBoardSearch constructor.
124
     *
125
     * @param FareMasterPricerTbSearch|null $options
126
     */
127
    public function __construct(FareMasterPricerTbSearch $options = null)
128
    {
129
        if ($options instanceof FareMasterPricerTbSearch) {
130
            $this->loadOptions($options);
131
        }
132
    }
133
134
    /**
135
     * @param FareMasterPricerTbSearch $options
136
     */
137
    protected function loadOptions(FareMasterPricerTbSearch $options)
138
    {
139
        $this->loadNrOfPaxAndResults($options);
140
141
        if ($options->doTicketabilityPreCheck === true ||
142
            $this->checkAnyNotEmpty($options->corporateCodesUnifares, $options->flightOptions)
143
        ) {
144
            $this->fareOptions = new MasterPricer\FareOptions(
145
                $options->flightOptions,
146
                $options->corporateCodesUnifares,
147
                $options->doTicketabilityPreCheck
148
            );
149
        }
150
151
        $passengerCounter = 1;
152
        $infantCounter = 1;
153
        foreach ($options->passengers as $passenger) {
154
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
155
        }
156
157
        $segmentCounter = 1;
158
        foreach ($options->itinerary as $itinerary) {
159
            $this->loadItinerary($itinerary, $segmentCounter);
160
        }
161
162
        if ($this->checkAnyNotEmpty(
163
            $options->cabinClass,
164
            $options->cabinOption,
165
            $options->requestedFlightTypes,
166
            $options->airlineOptions
167
        )) {
168
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
169
                $options->cabinClass,
170
                $options->cabinOption,
0 ignored issues
show
Documentation introduced by
$options->cabinOption is of type array<integer,string>, but the function expects a string|null.

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...
171
                $options->requestedFlightTypes,
172
                $options->airlineOptions
173
            );
174
        }
175
176
        if (!empty($options->priceToBeat)) {
177
            $this->priceToBeat = new MasterPricer\PriceToBeat(
178
                $options->priceToBeat,
179
                $options->priceToBeatCurrency
180
            );
181
        }
182
    }
183
184
    /**
185
     * @param MPPassenger $passenger
186
     * @param int $counter BYREF
187
     * @param int $infantCounter BYREF
188
     */
189
    protected function loadPassenger($passenger, &$counter, &$infantCounter)
190
    {
191
        $isInfant = ($passenger->type === 'INF');
192
193
        $paxRef = new MasterPricer\PaxReference(
194
            $isInfant ? $infantCounter : $counter,
195
            $isInfant,
196
            $passenger->type
197
        );
198
199
        if ($isInfant) {
200
            $infantCounter++;
201
        } else {
202
            $counter++;
203
        }
204
205
        if ($passenger->count > 1) {
206
            for ($i = 2; $i <= $passenger->count; $i++) {
207
                $tmpCount = ($isInfant) ? $infantCounter : $counter;
208
                $paxRef->traveller[] = new MasterPricer\Traveller($tmpCount, $isInfant);
209
210
                if ($isInfant) {
211
                    $infantCounter++;
212
                } else {
213
                    $counter++;
214
                }
215
            }
216
        }
217
218
        $this->paxReference[] = $paxRef;
219
    }
220
221
    /**
222
     * @param MPItinerary $itineraryOptions
223
     * @param int $counter BYREF
224
     */
225
    protected function loadItinerary($itineraryOptions, &$counter)
226
    {
227
        $tmpItinerary = new MasterPricer\Itinerary($counter);
228
229
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
230
            $itineraryOptions->departureLocation
231
        );
232
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
233
            $itineraryOptions->arrivalLocation
234
        );
235
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($itineraryOptions->date);
236
237
        $this->itinerary[] = $tmpItinerary;
238
239
        $counter++;
240
    }
241
242
    /**
243
     * @param FareMasterPricerTbSearch $options
244
     * @return void
245
     */
246
    protected function loadNrOfPaxAndResults(FareMasterPricerTbSearch $options)
247
    {
248
        if (is_int($options->nrOfRequestedPassengers) || is_int($options->nrOfRequestedResults)) {
249
            $this->numberOfUnit = new MasterPricer\NumberOfUnit(
250
                $options->nrOfRequestedPassengers,
251
                $options->nrOfRequestedResults
252
            );
253
        }
254
    }
255
}
256