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 |
||
| 41 | class MasterPricerTravelBoardSearch extends BaseMasterPricerMessage |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * @var mixed |
||
| 45 | */ |
||
| 46 | public $globalOptions; |
||
| 47 | /** |
||
| 48 | * @var MasterPricer\CustomerRef |
||
| 49 | */ |
||
| 50 | public $customerRef; |
||
| 51 | /** |
||
| 52 | * @var mixed |
||
| 53 | */ |
||
| 54 | public $formOfPaymentByPassenger; |
||
| 55 | /** |
||
| 56 | * @var mixed |
||
| 57 | */ |
||
| 58 | public $solutionFamily; |
||
| 59 | /** |
||
| 60 | * @var mixed[] |
||
| 61 | */ |
||
| 62 | public $passengerInfoGrp = []; |
||
| 63 | /** |
||
| 64 | * @var MasterPricer\FareFamilies[] |
||
| 65 | */ |
||
| 66 | public $fareFamilies = []; |
||
| 67 | /** |
||
| 68 | * @var MasterPricer\PriceToBeat |
||
| 69 | */ |
||
| 70 | public $priceToBeat; |
||
| 71 | /** |
||
| 72 | * @var mixed |
||
| 73 | */ |
||
| 74 | public $taxInfo; |
||
| 75 | /** |
||
| 76 | * @var MasterPricer\TravelFlightInfo |
||
| 77 | */ |
||
| 78 | public $travelFlightInfo; |
||
| 79 | /** |
||
| 80 | * @var array |
||
| 81 | */ |
||
| 82 | public $valueSearch = []; |
||
| 83 | /** |
||
| 84 | * Itinerary |
||
| 85 | * |
||
| 86 | * @var MasterPricer\Itinerary[] |
||
| 87 | */ |
||
| 88 | public $itinerary = []; |
||
| 89 | /** |
||
| 90 | * @var MPTicketingPriceScheme |
||
| 91 | */ |
||
| 92 | public $ticketingPriceScheme; |
||
| 93 | /** |
||
| 94 | * @var mixed |
||
| 95 | */ |
||
| 96 | public $ticketChangeInfo; |
||
| 97 | /** |
||
| 98 | * @var mixed |
||
| 99 | */ |
||
| 100 | public $combinationFareFamilies; |
||
| 101 | /** |
||
| 102 | * @var MasterPricer\FeeOption[] |
||
| 103 | */ |
||
| 104 | public $feeOption; |
||
| 105 | /** |
||
| 106 | * @var MasterPricer\OfficeIdDetails[] |
||
| 107 | */ |
||
| 108 | public $officeIdDetails; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * MasterPricerTravelBoardSearch constructor. |
||
| 112 | * |
||
| 113 | * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpTbSearchOptions|null $options |
||
| 114 | */ |
||
| 115 | public function __construct($options = null) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param FareMasterPricerTbSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpTbSearchOptions $options |
||
| 124 | */ |
||
| 125 | protected function loadOptions($options) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param string $officeId |
||
| 188 | */ |
||
| 189 | protected function loadOfficeId($officeId) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param MPItinerary $opt |
||
| 196 | * @param int $counter BYREF |
||
| 197 | */ |
||
| 198 | protected function loadItinerary($opt, &$counter) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @param MPFareFamily[] $fareFamilies |
||
| 245 | */ |
||
| 246 | protected function loadFareFamilies($fareFamilies) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Load Customer references |
||
| 255 | * |
||
| 256 | * @param string $dkNumber |
||
| 257 | */ |
||
| 258 | View Code Duplication | protected function loadCustomerRefs($dkNumber) |
|
| 268 | |||
| 269 | private function loadFeeOptions($feeOptions) |
||
| 277 | } |
||
| 278 |
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.