Completed
Push — master ( 833351...5fbac6 )
by Dieter
07:24
created

MasterPricerTravelBoardSearch::loadPassenger()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 23
cts 23
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 4
nop 3
crap 7
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\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 BaseMasterPricerMessage
38
{
39
    /**
40
     * @var mixed
41
     */
42
    public $globalOptions;
43
    /**
44
     * @var mixed
45
     */
46
    public $customerRef;
47
    /**
48
     * @var mixed
49
     */
50
    public $formOfPaymentByPassenger;
51
    /**
52
     * @var mixed
53
     */
54
    public $solutionFamily;
55
    /**
56
     * @var mixed[]
57
     */
58
    public $passengerInfoGrp = [];
59
    /**
60
     * @var MasterPricer\FareFamilies[]
61
     */
62
    public $fareFamilies = [];
63
    /**
64
     * @var MasterPricer\PriceToBeat
65
     */
66
    public $priceToBeat;
67
    /**
68
     * @var mixed
69
     */
70
    public $taxInfo;
71
    /**
72
     * @var MasterPricer\TravelFlightInfo
73
     */
74
    public $travelFlightInfo;
75
    /**
76
     * @var array
77
     */
78
    public $valueSearch = [];
79
    /**
80
     * @var array
81
     */
82
    public $buckets = [];
83
    /**
84
     * Itinerary
85
     *
86
     * @var MasterPricer\Itinerary[]
87
     */
88
    public $itinerary = [];
89
    /**
90
     * @var mixed
91
     */
92
    public $ticketChangeInfo;
93
    /**
94
     * @var mixed
95
     */
96
    public $combinationFareFamilies;
97
    /**
98
     * @var mixed
99
     */
100
    public $feeOption;
101
    /**
102
     * @var MasterPricer\OfficeIdDetails[]
103
     */
104
    public $officeIdDetails;
105
106
    /**
107
     * MasterPricerTravelBoardSearch constructor.
108
     *
109
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|null $options
110
     */
111 24
    public function __construct($options = null)
112
    {
113 24
        if ($options instanceof FareMasterPricerTbSearch || $options instanceof FareMasterPricerCalendarOptions) {
114 24
            $this->loadOptions($options);
115 24
        }
116 24
    }
117
118
    /**
119
     * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions $options
120
     */
121 24
    protected function loadOptions($options)
122 1
    {
123 24
        $this->loadNrOfPaxAndResults($options);
124
125 24
        $this->loadFareOptions($options);
126
127 24
        $passengerCounter = 1;
128 24
        $infantCounter = 1;
129 24
        foreach ($options->passengers as $passenger) {
130 23
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
131 24
        }
132
133 24
        $segmentCounter = 1;
134 24
        foreach ($options->itinerary as $itinerary) {
135 23
            $this->loadItinerary($itinerary, $segmentCounter);
136 24
        }
137
138 24
        foreach ($options->officeIds as $officeId) {
139 1
            $this->loadOfficeId($officeId);
140 24
        }
141
142 24
        if ($this->checkAnyNotEmpty(
143 24
            $options->cabinClass,
144 24
            $options->cabinOption,
145 24
            $options->requestedFlightTypes,
146 24
            $options->airlineOptions
147 24
        )) {
148 6
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
149 6
                $options->cabinClass,
150 6
                $options->cabinOption,
151 6
                $options->requestedFlightTypes,
152 6
                $options->airlineOptions
153 6
            );
154 6
        }
155
156 24
        if (!empty($options->priceToBeat)) {
157 1
            $this->priceToBeat = new MasterPricer\PriceToBeat(
158 1
                $options->priceToBeat,
159 1
                $options->priceToBeatCurrency
160 1
            );
161 1
        }
162
163 24
        $this->loadFareFamilies($options->fareFamilies);
164 24
    }
165
166
    /**
167
     * @param string $officeId
168
     */
169 1
    protected function loadOfficeId($officeId)
170
    {
171 1
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
172 1
    }
173
174
    /**
175
     * @param MPItinerary $itineraryOptions
176
     * @param int $counter BYREF
177
     */
178 23
    protected function loadItinerary($itineraryOptions, &$counter)
179
    {
180 23
        $tmpItinerary = new MasterPricer\Itinerary($counter);
181
182 23
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
183 23
            $itineraryOptions->departureLocation
184 23
        );
185 23
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
186 23
            $itineraryOptions->arrivalLocation
187 23
        );
188 23
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($itineraryOptions->date);
189
190 23
        $this->itinerary[] = $tmpItinerary;
191
192 23
        $counter++;
193 23
    }
194
195
    /**
196
     * @param MPFareFamily[] $fareFamilies
197
     */
198 24
    protected function loadFareFamilies($fareFamilies)
199
    {
200 24
        foreach ($fareFamilies as $fareFamily) {
201 2
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
202 24
        }
203 24
    }
204
}
205