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 |
||
| 37 | class MasterPricerTravelBoardSearch extends BaseWsMessage |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * Number of seats, recommendations. |
||
| 41 | * |
||
| 42 | * @var MasterPricer\NumberOfUnit |
||
| 43 | */ |
||
| 44 | public $numberOfUnit; |
||
| 45 | /** |
||
| 46 | * @var mixed |
||
| 47 | */ |
||
| 48 | public $globalOptions; |
||
| 49 | /** |
||
| 50 | * Traveler Details |
||
| 51 | * |
||
| 52 | * @var MasterPricer\PaxReference[] |
||
| 53 | */ |
||
| 54 | public $paxReference = []; |
||
| 55 | /** |
||
| 56 | * @var mixed |
||
| 57 | */ |
||
| 58 | public $customerRef; |
||
| 59 | /** |
||
| 60 | * @var mixed |
||
| 61 | */ |
||
| 62 | public $formOfPaymentByPassenger; |
||
| 63 | /** |
||
| 64 | * @var mixed |
||
| 65 | */ |
||
| 66 | public $solutionFamily; |
||
| 67 | /** |
||
| 68 | * @var mixed |
||
| 69 | */ |
||
| 70 | public $fareFamilies; |
||
| 71 | /** |
||
| 72 | * @var MasterPricer\FareOptions |
||
| 73 | */ |
||
| 74 | public $fareOptions; |
||
| 75 | /** |
||
| 76 | * @var mixed |
||
| 77 | */ |
||
| 78 | public $priceToBeat; |
||
| 79 | /** |
||
| 80 | * @var mixed |
||
| 81 | */ |
||
| 82 | public $taxInfo; |
||
| 83 | /** |
||
| 84 | * @var MasterPricer\TravelFlightInfo |
||
| 85 | */ |
||
| 86 | public $travelFlightInfo; |
||
| 87 | |||
| 88 | public $valueSearch = []; |
||
| 89 | /** |
||
| 90 | * Itinerary |
||
| 91 | * |
||
| 92 | * @var MasterPricer\Itinerary[] |
||
| 93 | */ |
||
| 94 | public $itinerary = []; |
||
| 95 | /** |
||
| 96 | * @var mixed |
||
| 97 | */ |
||
| 98 | public $ticketChangeInfo; |
||
| 99 | /** |
||
| 100 | * @var mixed |
||
| 101 | */ |
||
| 102 | public $combinationFareFamilies; |
||
| 103 | /** |
||
| 104 | * @var mixed |
||
| 105 | */ |
||
| 106 | public $feeOption; |
||
| 107 | /** |
||
| 108 | * @var mixed |
||
| 109 | */ |
||
| 110 | public $officeIdDetails; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * MasterPricerTravelBoardSearch constructor. |
||
| 114 | * |
||
| 115 | * @param FareMasterPricerTbSearch|null $options |
||
| 116 | */ |
||
| 117 | public function __construct(FareMasterPricerTbSearch $options = null) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param FareMasterPricerTbSearch $options |
||
| 126 | */ |
||
| 127 | protected function loadOptions(FareMasterPricerTbSearch $options) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param MPPassenger $passenger |
||
| 157 | * @param int $counter BYREF |
||
| 158 | * @param int $infantCounter BYREF |
||
| 159 | */ |
||
| 160 | protected function loadPassenger($passenger, &$counter, &$infantCounter) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param MPItinerary $itinerary |
||
| 194 | * @param int $counter BYREF |
||
| 195 | */ |
||
| 196 | protected function loadItinerary($itinerary, &$counter) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param FareMasterPricerTbSearch $options |
||
| 211 | * @return void |
||
| 212 | */ |
||
| 213 | protected function loadNrOfPaxAndResults(FareMasterPricerTbSearch $options) |
||
| 231 | } |
||
| 232 |
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.