Completed
Push — master ( 738038...14ebb8 )
by Dieter
11:17
created

ExtremeSearch::loadDestinationCountries()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
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\PriceXplorer;
24
25
use Amadeus\Client\RequestOptions\PriceXplorerExtremeSearchOptions;
26
use Amadeus\Client\Struct\BaseWsMessage;
27
28
/**
29
 * ExtremeSearch
30
 *
31
 * @package Amadeus\Client\Struct\PriceXplorer
32
 * @author Dieter Devlieghere <[email protected]>
33
 */
34
class ExtremeSearch extends BaseWsMessage
35
{
36
    /**
37
     * Itinerary information group
38
     *
39
     * @var ItineraryGrp[]
40
     */
41
    public $itineraryGrp = [];
42
43
    /**
44
     * Budget info
45
     *
46
     * @var Budget
47
     */
48
    public $budget;
49
50
    /**
51
     * Departure dates ranges
52
     *
53
     * @var TravelDates
54
     */
55
    public $travelDates;
56
57
    /**
58
     * Stay duration and flexibility
59
     *
60
     * @var StayDuration
61
     */
62
    public $stayDuration;
63
64
    /**
65
     * Attribute Information
66
     *
67
     * @var AttributeInfo[]
68
     */
69
    public $attributeInfo = [];
70
71
    /**
72
     * Option description : Price result distribution, ...
73
     *
74
     * @var SelectionDetailsGroup[]
75
     */
76
    public $selectionDetailsGroup = [];
77
78
    /**
79
     * List of departure days
80
     *
81
     * @var DepartureDays[]
82
     */
83
    public $departureDays = [];
84
85
    /**
86
     * Airline information
87
     *
88
     * @var AirlineInfo[]
89
     */
90
    public $airlineInfo = [];
91
92
    /**
93
     * List of Office Id Details
94
     *
95
     * @var OfficeIdInfo[]
96
     */
97
    public $officeIdInfo = [];
98
99
    /**
100
     * Construct PriceXplorer_ExtremeSearch Request message
101
     *
102
     * @param PriceXplorerExtremeSearchOptions $params
103
     */
104 6
    public function __construct(PriceXplorerExtremeSearchOptions $params)
105
    {
106 6
        $this->itineraryGrp[] = new ItineraryGrp($params->origin);
107
108 6
        $this->loadDepartureDateLimits($params);
109
110 6
        if ($params->searchOffice !== null) {
111 6
            $this->officeIdInfo[] = new OfficeIdInfo($params->searchOffice);
112 6
        }
113
114 6
        $this->loadBudget($params->maxBudget, $params->minBudget, $params->currency);
115
116 6
        $this->loadDestinations($params);
117
118 6
        $this->loadDepartureDaysOutIn($params);
119
120 6
        $this->loadStayDuration($params->stayDurationDays, $params->stayDurationFlexibilityDays);
121
122 6
        $this->loadCheapestQualifiers($params->returnCheapestNonStop, $params->returnCheapestOverall);
123
124 6
        $this->loadResultAggregation($params->resultAggregationOption);
125 6
    }
126
127
    /**
128
     * @param int|null $maxBudget
129
     * @param int|null $minBudget
130
     * @param string|null $currency
131
     */
132 6
    protected function loadBudget($maxBudget, $minBudget, $currency)
133
    {
134 6
        if (($maxBudget !== null || $minBudget !== null) && $currency !== null) {
135 1
            $this->budget = new Budget(
136 1
                $maxBudget,
137 1
                $minBudget,
138
                $currency
139 1
            );
140 1
        }
141 6
    }
142
143
    /**
144
     * @param int|null $stayDuration
145
     * @param int|null $flexibility
146
     */
147 6
    protected function loadStayDuration($stayDuration, $flexibility)
148
    {
149 6
        if ($stayDuration !== null) {
150 1
            $this->stayDuration = new StayDuration($stayDuration);
151
152 1
            if ($flexibility !== null) {
153 1
                $this->stayDuration->flexibilityInfo = new FlexibilityInfo($flexibility);
154 1
            }
155 1
        }
156 6
    }
157
158
    /**
159
     * @param bool $cheapestNonStop
160
     * @param bool $cheapestOverall
161
     */
162 6
    protected function loadCheapestQualifiers($cheapestNonStop, $cheapestOverall)
163
    {
164 6
        if ($cheapestNonStop || $cheapestOverall) {
165 1
            $this->selectionDetailsGroup[] = new SelectionDetailsGroup($cheapestNonStop, $cheapestOverall);
166 1
        }
167 6
    }
168
169
    /**
170
     * @param string $resultAggregationOption
171
     */
172 6
    protected function loadResultAggregation($resultAggregationOption)
173
    {
174 6
        if ($resultAggregationOption !== null) {
175 6
            $groupTypes = $this->makeAggregationGroupTypes($resultAggregationOption);
176
177 6
            $this->attributeInfo[] = new AttributeInfo(
178 6
                AttributeInfo::FUNC_GROUPING,
179
                $groupTypes
180 6
            );
181 6
        }
182 6
    }
183
184
    /**
185
     * @param string $groupTypeString
186
     * @return array
187
     */
188 6
    protected function makeAggregationGroupTypes($groupTypeString)
189
    {
190 6
        $result = [];
191
192
        switch ($groupTypeString) {
193 6
            case PriceXplorerExtremeSearchOptions::AGGR_DEST:
194 1
                $result[] = AttributeDetails::TYPE_DESTINATION;
195 1
                break;
196 6
            case PriceXplorerExtremeSearchOptions::AGGR_COUNTRY:
197 2
                $result[] = AttributeDetails::TYPE_COUNTRY;
198 2
                break;
199 5
            case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK:
200 1
                $result[] = AttributeDetails::TYPE_DESTINATION;
201 1
                $result[] = AttributeDetails::TYPE_WEEK;
202 1
                break;
203 5 View Code Duplication
            case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK_DEPART:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
204 1
                $result[] = AttributeDetails::TYPE_DESTINATION;
205 1
                $result[] = AttributeDetails::TYPE_WEEK;
206 1
                $result[] = AttributeDetails::TYPE_DEPARTURE_DAY;
207 1
                break;
208 4 View Code Duplication
            case PriceXplorerExtremeSearchOptions::AGGR_DEST_WEEK_DEPART_STAY:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209 4
                $result[] = AttributeDetails::TYPE_DESTINATION;
210 4
                $result[] = AttributeDetails::TYPE_WEEK;
211 4
                $result[] = AttributeDetails::TYPE_DEPARTURE_DAY;
212 4
                $result[] = AttributeDetails::TYPE_STAY_DURATION;
213 4
                break;
214
        }
215
216 6
        return $result;
217
    }
218
219
    /**
220
     * @param PriceXplorerExtremeSearchOptions $params
221
     *
222
     */
223 6
    protected function loadDepartureDateLimits(PriceXplorerExtremeSearchOptions $params)
224
    {
225 6
        if ($params->earliestDepartureDate instanceof \DateTime || $params->latestDepartureDate instanceof \DateTime) {
226 6
            $this->travelDates = new TravelDates($params->earliestDepartureDate, $params->latestDepartureDate);
227 6
        }
228 6
    }
229
230
    /**
231
     * @param PriceXplorerExtremeSearchOptions $params
232
     *
233
     */
234 6
    protected function loadDestinations(PriceXplorerExtremeSearchOptions $params)
235
    {
236 6
        foreach ($params->destinations as $destination) {
237 5
            $this->itineraryGrp[] = new ItineraryGrp(null, $destination);
238 6
        }
239
240 6
        foreach ($params->destinationCountries as $destinationCountry) {
241 1
            $tmpGrp = new ItineraryGrp();
242
243 1
            $tmpGrp->locationInfo = new LocationInfo(LocationInfo::LOC_COUNTRY);
244
245 1
            $tmpGrp->locationInfo->locationDescription = new LocationIdentificationType();
246 1
            $tmpGrp->locationInfo->locationDescription->qualifier = LocationIdentificationType::QUAL_DESTINATION;
247 1
            $tmpGrp->locationInfo->locationDescription->code = $destinationCountry;
248
249 1
            $this->itineraryGrp[] = $tmpGrp;
250 6
        }
251 6
    }
252
253
    /**
254
     * @param PriceXplorerExtremeSearchOptions $params
255
     *
256
     */
257 6
    protected function loadDepartureDaysOutIn(PriceXplorerExtremeSearchOptions $params)
258
    {
259 6
        if (!empty($params->departureDaysInbound)) {
260 1
            $this->departureDays[] = new DepartureDays(
261 1
                $params->departureDaysInbound,
262
                SelectionDetails::OPT_INBOUND_DEP_DAYS
263 1
            );
264 1
        }
265 6
        if (!empty($params->departureDaysOutbound)) {
266 1
            $this->departureDays[] = new DepartureDays(
267 1
                $params->departureDaysOutbound,
268
                SelectionDetails::OPT_OUTBOUND_DEP_DAYS
269 1
            );
270 1
        }
271 6
    }
272
}
273