Completed
Push — master ( 6ff209...20c17c )
by Dieter
06:34
created

MasterPricerTravelBoardSearch::loadOptions()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 50
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 41
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 50
ccs 41
cts 41
cp 1
rs 8.6315
cc 6
eloc 32
nc 32
nop 1
crap 6
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 mixed
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 28
    public function __construct($options = null)
115
    {
116 28
        if ($options instanceof FareMasterPricerTbSearch) {
117 28
            $this->loadOptions($options);
118 28
        }
119 28
    }
120
121
    /**
122
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpTbSearchOptions $options
123
     */
124 28
    protected function loadOptions($options)
125
    {
126 28
        $this->loadNrOfPaxAndResults($options);
127
128 28
        $this->loadFareOptions($options);
129
130 28
        $passengerCounter = 1;
131 28
        $infantCounter = 1;
132 28
        foreach ($options->passengers as $passenger) {
133 26
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
134 28
        }
135
136 28
        $segmentCounter = 1;
137 28
        foreach ($options->itinerary as $itinerary) {
138 26
            $this->loadItinerary($itinerary, $segmentCounter);
139 28
        }
140
141 28
        foreach ($options->officeIds as $officeId) {
142 1
            $this->loadOfficeId($officeId);
143 28
        }
144
145 28
        if ($this->checkAnyNotEmpty(
146 28
            $options->cabinClass,
147 28
            $options->cabinOption,
148 28
            $options->requestedFlightTypes,
149 28
            $options->airlineOptions,
150 28
            $options->progressiveLegsMin,
151 28
            $options->progressiveLegsMax
152 28
        )) {
153 7
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
154 7
                $options->cabinClass,
155 7
                $options->cabinOption,
156 7
                $options->requestedFlightTypes,
157 7
                $options->airlineOptions,
158 7
                $options->progressiveLegsMin,
159 7
                $options->progressiveLegsMax
160 7
            );
161 7
        }
162
163 28
        if (!empty($options->priceToBeat)) {
164 1
            $this->priceToBeat = new MasterPricer\PriceToBeat(
165 1
                $options->priceToBeat,
166 1
                $options->priceToBeatCurrency
167 1
            );
168 1
        }
169
170 28
        $this->loadFareFamilies($options->fareFamilies);
171
172 28
        $this->loadCustomerRefs($options->dkNumber);
173 28
    }
174
175
    /**
176
     * @param string $officeId
177
     */
178 1
    protected function loadOfficeId($officeId)
179
    {
180 1
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
181 1
    }
182
183
    /**
184
     * @param MPItinerary $itineraryOptions
185
     * @param int $counter BYREF
186
     */
187 26
    protected function loadItinerary($itineraryOptions, &$counter)
188
    {
189 26
        $segmentRef = $counter;
190
191 26
        if (!empty($itineraryOptions->segmentReference)) {
192 1
            $segmentRef = $itineraryOptions->segmentReference;
193 1
        }
194
195 26
        $tmpItinerary = new MasterPricer\Itinerary($segmentRef);
196
197 26
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
198 26
            $itineraryOptions->departureLocation
199 26
        );
200 26
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
201 26
            $itineraryOptions->arrivalLocation
202 26
        );
203 26
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($itineraryOptions->date);
204
205 26
        $this->itinerary[] = $tmpItinerary;
206
207 26
        $counter++;
208 26
    }
209
210
    /**
211
     * @param MPFareFamily[] $fareFamilies
212
     */
213 28
    protected function loadFareFamilies($fareFamilies)
214
    {
215 28
        foreach ($fareFamilies as $fareFamily) {
216 2
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
217 28
        }
218 28
    }
219
220
    /**
221
     * Load Customer references
222
     *
223
     * @param string $dkNumber
224
     */
225 28
    protected function loadCustomerRefs($dkNumber)
226
    {
227 28
        if (!is_null($dkNumber)) {
228 1
            $this->customerRef = new MasterPricer\CustomerRef();
229 1
            $this->customerRef->customerReferences[] = new MasterPricer\CustomerReferences(
230 1
                $dkNumber,
231
                MasterPricer\CustomerReferences::QUAL_AGENCY_GROUPING_ID
232 1
            );
233 1
        }
234 28
    }
235
}
236