Test Failed
Pull Request — master (#344)
by Andrew
09:56
created

MasterPricerExpertSearch   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 229
Duplicated Lines 22.27 %

Coupling/Cohesion

Components 1
Dependencies 14

Test Coverage

Coverage 98.9%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 14
dl 51
loc 229
ccs 90
cts 91
cp 0.989
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A loadOfficeId() 0 4 1
A __construct() 0 6 2
B loadOptions() 21 56 6
A loadItinerary() 20 43 3
A loadFareFamilies() 0 6 2
A loadCustomerRefs() 10 10 2
A loadFeeOptions() 0 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\FareMasterPricerExSearchOptions;
29
use Amadeus\Client\RequestOptions\TicketAtcShopperMpTbSearchOptions;
30
use Amadeus\Client\Struct\Fare\MasterPricer;
31
32
/**
33
 * Fare_MasterPricerExpertSearch message structure
34
 *
35
 * @package Amadeus\Client\Struct\Fare
36
 * @author Dieter Devlieghere <[email protected]>
37
 */
38
class MasterPricerExpertSearch extends BaseMasterPricerMessage
39
{
40
41
    /**
42
     * @var mixed
43
     */
44
    public $globalOptions;
45
    /**
46
     * @var MasterPricer\CustomerRef
47
     */
48
    public $customerRef;
49
    /**
50
     * @var mixed
51
     */
52
    public $formOfPaymentByPassenger;
53
    /**
54
     * @var mixed
55
     */
56
    public $solutionFamily;
57
    /**
58
     * @var mixed[]
59
     */
60
    public $passengerInfoGrp = [];
61
    /**
62
     * @var MasterPricer\FareFamilies[]
63
     */
64
    public $fareFamilies = [];
65
    /**
66
     * @var MasterPricer\PriceToBeat
67
     */
68
    public $priceToBeat;
69
    /**
70
     * @var mixed
71
     */
72
    public $taxInfo;
73
    /**
74
     * @var MasterPricer\TravelFlightInfo
75
     */
76
    public $travelFlightInfo;
77
    /**
78
     * @var array
79
     */
80
    public $valueSearch = [];
81
    /**
82
     * Itinerary
83
     *
84
     * @var MasterPricer\Itinerary[]
85
     */
86
    public $itinerary = [];
87
    /**
88
     * @var mixed
89
     */
90
    public $ticketChangeInfo;
91
    /**
92
     * @var mixed
93
     */
94
    public $combinationFareFamilies;
95
    /**
96
     * @var MasterPricer\FeeOption[]
97
     */
98
    public $feeOption;
99
    /**
100
     * @var MasterPricer\OfficeIdDetails[]
101
     */
102
    public $officeIdDetails;
103
104
    /**
105
     * MasterPricerExpertSearch constructor.
106
     *
107
     * @param FareMasterPricerExSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpExSearchOptions|null $options
108
     */
109 99
    public function __construct($options = null)
110
    {
111 99
        if ($options instanceof FareMasterPricerExSearchOptions) {
112 99
            $this->loadOptions($options);
113
        }
114 99
    }
115
116
    /**
117
     * @param FareMasterPricerExSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpExSearchOptions $options
118
     */
119 99
    protected function loadOptions($options)
120
    {
121 99
        $this->loadNumberOfUnits($options);
122
123 99
        $this->loadFareOptions($options);
124
125 99
        $passengerCounter = 1;
126 99
        $infantCounter = 1;
127 99
        foreach ($options->passengers as $passenger) {
128 90
            $this->loadPassenger($passenger, $passengerCounter, $infantCounter);
129
        }
130
131 99
        $segmentCounter = 1;
132 99
        foreach ($options->itinerary as $itinerary) {
133 90
            $this->loadItinerary($itinerary, $segmentCounter);
134
        }
135
136 99
        foreach ($options->officeIds as $officeId) {
137 3
            $this->loadOfficeId($officeId);
138
        }
139
140 99 View Code Duplication
        if ($this->checkAnyNotEmpty(
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...
141 99
            $options->cabinClass,
142 99
            $options->cabinOption,
143 99
            $options->requestedFlightTypes,
144 99
            $options->airlineOptions,
145 99
            $options->progressiveLegsMin,
146 99
            $options->progressiveLegsMax,
147 99
            $options->maxLayoverPerConnectionHours,
148 99
            $options->maxLayoverPerConnectionMinutes
149
        )) {
150 27
            $this->travelFlightInfo = new MasterPricer\TravelFlightInfo(
151 27
            $options->cabinClass,
152 27
            $options->cabinOption,
153 27
            $options->requestedFlightTypes,
154 27
            $options->airlineOptions,
155 27
            $options->progressiveLegsMin,
156 27
            $options->progressiveLegsMax,
157 27
            $options->maxLayoverPerConnectionHours,
158 27
            $options->maxLayoverPerConnectionMinutes
159
        );
160
        }
161
162 99
        if (!empty($options->priceToBeat)) {
163 3
            $this->priceToBeat = new MasterPricer\PriceToBeat(
164 3
                $options->priceToBeat,
165 3
                $options->priceToBeatCurrency
166
            );
167
        }
168
169 99
        $this->loadFareFamilies($options->fareFamilies);
170
171 99
        $this->loadCustomerRefs($options->dkNumber);
172
173 99
        $this->loadFeeOptions($options->feeOption);
174 99
    }
175
176
    /**
177
     * @param string $officeId
178
     */
179 3
    protected function loadOfficeId($officeId)
180
    {
181 3
        $this->officeIdDetails[] = new MasterPricer\OfficeIdDetails($officeId);
182 3
    }
183
184
    /**
185
     * @param MPItinerary $opt
186
     * @param int $counter BYREF
187
     */
188 90
    protected function loadItinerary($opt, &$counter)
189
    {
190 90
        $segmentRef = $counter;
191
192 90
        if (!empty($opt->segmentReference)) {
193
            $segmentRef = $opt->segmentReference;
194
        }
195
196 90
        $tmpItinerary = new MasterPricer\Itinerary($segmentRef);
197
198 90
        $tmpItinerary->departureLocalization = new MasterPricer\DepartureLocalization(
199 90
            $opt->departureLocation
200
        );
201 90
        $tmpItinerary->arrivalLocalization = new MasterPricer\ArrivalLocalization(
202 90
            $opt->arrivalLocation
203
        );
204 90
        $tmpItinerary->timeDetails = new MasterPricer\TimeDetails($opt->date);
205
206 90 View Code Duplication
        if ($this->checkAnyNotEmpty(
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...
207 90
            $opt->airlineOptions,
208 90
            $opt->requestedFlightTypes,
209 90
            $opt->includedConnections,
210 90
            $opt->excludedConnections,
211 90
            $opt->nrOfConnections,
212 90
            $opt->cabinClass,
213 90
            $opt->cabinOption
214
        )) {
215 15
            $tmpItinerary->flightInfo = new MasterPricer\FlightInfo(
216 15
                $opt->airlineOptions,
217 15
                $opt->requestedFlightTypes,
218 15
                $opt->includedConnections,
219 15
                $opt->excludedConnections,
220 15
                $opt->nrOfConnections,
221 15
                null,
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a boolean.

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...
222 15
                $opt->cabinClass,
223 15
                $opt->cabinOption
224
            );
225
        }
226
227 90
        $this->itinerary[] = $tmpItinerary;
228
229 90
        $counter++;
230 90
    }
231
232
    /**
233
     * @param MPFareFamily[] $fareFamilies
234
     */
235 99
    protected function loadFareFamilies($fareFamilies)
236
    {
237 99
        foreach ($fareFamilies as $fareFamily) {
238 6
            $this->fareFamilies[] = new MasterPricer\FareFamilies($fareFamily);
239
        }
240 99
    }
241
242
    /**
243
     * Load Customer references
244
     *
245
     * @param string $dkNumber
246
     */
247 99 View Code Duplication
    protected function loadCustomerRefs($dkNumber)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
248
    {
249 99
        if (!is_null($dkNumber)) {
250 3
            $this->customerRef = new MasterPricer\CustomerRef();
251 3
            $this->customerRef->customerReferences[] = new MasterPricer\CustomerReferences(
252 3
                $dkNumber,
253 3
                MasterPricer\CustomerReferences::QUAL_AGENCY_GROUPING_ID
254
            );
255
        }
256 99
    }
257
258 99
    private function loadFeeOptions($feeOptions)
259
    {
260 99
        if (!is_null($feeOptions)) {
261 99
            foreach ($feeOptions as $feeOption) {
262 3
                $this->feeOption[] = new MasterPricer\FeeOption($feeOption);
263
            }
264
        }
265 99
    }
266
}
267