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 |
||
| 49 | class IntegratedPricing extends BasePricingMessage |
||
| 50 | { |
||
| 51 | /** |
||
| 52 | * @var PricingOption[] |
||
| 53 | */ |
||
| 54 | public $pricingOption = []; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * IntegratedPricing constructor. |
||
| 58 | * |
||
| 59 | * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions|null $options |
||
| 60 | */ |
||
| 61 | 64 | public function __construct($options = null) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * @param ServiceIntegratedPricingOptions|ServiceIntegratedCatalogueOptions $options |
||
| 70 | * @return PricingOption[] |
||
| 71 | */ |
||
| 72 | 64 | public static function loadPricingOptions($options) |
|
| 164 | |||
| 165 | /** |
||
| 166 | * @param FareBasis[] $pricingsFareBasis |
||
| 167 | * @return PricingOptionGroup[] |
||
| 168 | */ |
||
| 169 | View Code Duplication | protected static function makePricingOptionFareBasisOverride($pricingsFareBasis) |
|
| 170 | { |
||
| 171 | $opt = []; |
||
| 172 | |||
| 173 | if ($pricingsFareBasis !== null) { |
||
| 174 | foreach ($pricingsFareBasis as $pricingFareBasis) { |
||
| 175 | $po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE); |
||
| 176 | |||
| 177 | //Support for legacy fareBasisPrimaryCode to be removed when breaking BC: |
||
| 178 | $po->optionDetail = new OptionDetail( |
||
| 179 | $pricingFareBasis->fareBasisPrimaryCode.$pricingFareBasis->fareBasisCode |
||
| 180 | ); |
||
| 181 | |||
| 182 | //Support for legacy segmentReference to be removed when breaking BC: |
||
| 183 | $po->paxSegTstReference = new PaxSegTstReference( |
||
| 184 | $pricingFareBasis->references, |
||
| 185 | $pricingFareBasis->segmentReference |
||
| 186 | ); |
||
| 187 | |||
| 188 | $opt[] = $po; |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | return $opt; |
||
| 193 | } |
||
| 194 | |||
| 195 | |||
| 196 | /** |
||
| 197 | * @param string|null $validatingCarrier |
||
| 198 | * @return PricingOption[] |
||
| 199 | */ |
||
| 200 | View Code Duplication | protected static function makePricingOptionForValidatingCarrier($validatingCarrier) |
|
| 201 | { |
||
| 202 | $opt = []; |
||
| 203 | |||
| 204 | if ($validatingCarrier !== null) { |
||
| 205 | $po = new PricingOption(PricingOptionKey::OVERRIDE_VALIDATING_CARRIER); |
||
| 206 | |||
| 207 | $po->carrierInformation = new CarrierInformation($validatingCarrier); |
||
| 208 | |||
| 209 | $opt[] = $po; |
||
| 210 | } |
||
| 211 | |||
| 212 | return $opt; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @param string|null $currency |
||
| 217 | * @return PricingOption[] |
||
| 218 | */ |
||
| 219 | View Code Duplication | protected static function makePricingOptionForCurrencyOverride($currency) |
|
| 220 | { |
||
| 221 | $opt = []; |
||
| 222 | |||
| 223 | if ($currency !== null) { |
||
| 224 | $po = new PricingOption(PricingOptionKey::OVERRIDE_CURRENCY); |
||
| 225 | |||
| 226 | $po->currency = new Currency($currency); |
||
| 227 | |||
| 228 | $opt[] = $po; |
||
| 229 | } |
||
| 230 | |||
| 231 | return $opt; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param string $overrideCode |
||
| 236 | * @param string|array|null $options |
||
| 237 | * @param PaxSegRef[] $references |
||
| 238 | * @return PricingOption[] |
||
| 239 | */ |
||
| 240 | protected function makePricingOptionWithOptionDetailAndRefs($overrideCode, $options, $references) |
||
| 241 | { |
||
| 242 | $opt = []; |
||
| 243 | |||
| 244 | if ($options !== null) { |
||
| 245 | $po = new PricingOption($overrideCode); |
||
| 246 | |||
| 247 | $po->optionDetail = new OptionDetail($options); |
||
| 248 | |||
| 249 | if (!empty($references)) { |
||
| 250 | $po->paxSegTstReference = new PaxSegTstReference($references); |
||
| 251 | } |
||
| 252 | |||
| 253 | $opt[] = $po; |
||
| 254 | } |
||
| 255 | |||
| 256 | return $opt; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param \DateTime|null $dateOverride |
||
| 261 | * @return PricingOption[] |
||
| 262 | */ |
||
| 263 | View Code Duplication | protected static function loadDateOverride($dateOverride) |
|
| 264 | { |
||
| 265 | $opt = []; |
||
| 266 | |||
| 267 | if ($dateOverride instanceof \DateTime) { |
||
| 268 | $po = new PricingOption(PricingOptionKey::OVERRIDE_PRICING_DATE); |
||
| 269 | |||
| 270 | $po->dateInformation = new DateInformation( |
||
| 271 | DateInformation::OPT_DATE_OVERRIDE, |
||
| 272 | $dateOverride |
||
| 273 | ); |
||
| 274 | |||
| 275 | $opt[] = $po; |
||
| 276 | } |
||
| 277 | |||
| 278 | return $opt; |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param string|null $posOverride |
||
| 283 | * @return PricingOption[] |
||
| 284 | */ |
||
| 285 | View Code Duplication | protected static function loadPointOverrides($posOverride) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @param FormOfPayment[] $formOfPayment |
||
| 305 | * @return PricingOption[] |
||
| 306 | */ |
||
| 307 | View Code Duplication | protected static function loadFormOfPaymentOverride($formOfPayment) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * @param FrequentFlyer[] $frequentFlyers |
||
| 324 | * @return PricingOption[] |
||
| 325 | */ |
||
| 326 | View Code Duplication | protected static function loadFrequentFlyerOverride($frequentFlyers) |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @param PaxSegRef[] $references |
||
| 343 | * @return PricingOption[] |
||
| 344 | */ |
||
| 345 | View Code Duplication | protected static function loadReferences($references) |
|
| 359 | |||
| 360 | /** |
||
| 361 | * @param string[] $overrideOptions |
||
| 362 | * @param PricingOption[] $priceOptions |
||
| 363 | * @return PricingOption[] |
||
| 364 | */ |
||
| 365 | View Code Duplication | protected static function makeOverrideOptions($overrideOptions, $priceOptions) |
|
| 366 | { |
||
| 367 | $opt = []; |
||
| 368 | |||
| 369 | foreach ($overrideOptions as $overrideOption) { |
||
| 370 | if (!self::hasPricingGroup($overrideOption, $priceOptions)) { |
||
| 371 | $opt[] = new PricingOption($overrideOption); |
||
| 372 | } |
||
| 373 | } |
||
| 374 | |||
| 375 | return $opt; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Merges Pricing options |
||
| 380 | * |
||
| 381 | * @param PricingOption[] $existingOptions |
||
| 382 | * @param PricingOption[] $newOptions |
||
| 383 | * @return PricingOption[] merged array |
||
| 384 | */ |
||
| 385 | protected static function mergeOptions($existingOptions, $newOptions) |
||
| 396 | } |
||
| 397 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.