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 |
||
| 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 | public function __construct(PriceXplorerExtremeSearchOptions $params) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param int|null $maxBudget |
||
| 133 | * @param int|null $minBudget |
||
| 134 | * @param string|null $currency |
||
| 135 | */ |
||
| 136 | protected function loadBudget($maxBudget, $minBudget, $currency) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param array $destinationCountries |
||
| 149 | */ |
||
| 150 | protected function loadDestinationCountries($destinationCountries) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param int|null $stayDuration |
||
| 167 | * @param int|null $flexibility |
||
| 168 | */ |
||
| 169 | protected function loadStayDuration($stayDuration, $flexibility) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param bool $cheapestNonStop |
||
| 182 | * @param bool $cheapestOverall |
||
| 183 | */ |
||
| 184 | protected function loadCheapestQualifiers($cheapestNonStop, $cheapestOverall) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param string $resultAggregationOption |
||
| 217 | */ |
||
| 218 | protected function loadResultAggregation($resultAggregationOption) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @param string $groupTypeString |
||
| 234 | * @return array |
||
| 235 | */ |
||
| 236 | protected function makeAggregationGroupTypes($groupTypeString) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 269 | * |
||
| 270 | */ |
||
| 271 | protected function loadDepartureDateLimits(PriceXplorerExtremeSearchOptions $params) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 280 | * |
||
| 281 | */ |
||
| 282 | protected function loadDestinations(PriceXplorerExtremeSearchOptions $params) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param PriceXplorerExtremeSearchOptions $params |
||
| 293 | * |
||
| 294 | */ |
||
| 295 | protected function loadDepartureDaysOutIn(PriceXplorerExtremeSearchOptions $params) |
||
| 307 | } |
||
| 308 |
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.