Passed
Push — master ( e3318f...227ab8 )
by Dieter
08:19
created

MasterPricerTravelBoardSearch   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 211
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 14

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 18
lcom 1
cbo 14
dl 0
loc 211
c 1
b 0
f 0
ccs 92
cts 92
cp 1
rs 10

7 Methods

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