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 |
||
| 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 | public function __construct($options = null) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param FareMasterPricerExSearch|FareMasterPricerCalendarOptions|TicketAtcShopperMpExSearchOptions $options |
||
| 118 | */ |
||
| 119 | protected function loadOptions($options) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param string $officeId |
||
| 178 | */ |
||
| 179 | protected function loadOfficeId($officeId) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param MPItinerary $itineraryOptions |
||
| 186 | * @param int $counter BYREF |
||
| 187 | */ |
||
| 188 | protected function loadItinerary($itineraryOptions, &$counter) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param MPFareFamily[] $fareFamilies |
||
| 213 | */ |
||
| 214 | protected function loadFareFamilies($fareFamilies) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Load Customer references |
||
| 223 | * |
||
| 224 | * @param string $dkNumber |
||
| 225 | */ |
||
| 226 | View Code Duplication | protected function loadCustomerRefs($dkNumber) |
|
| 236 | |||
| 237 | private function loadFeeOptions($feeOptions) |
||
| 245 | } |
||
| 246 |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.