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 |
||
| 3 | class OrderStep_RecordDeviceDetails extends OrderStep implements OrderStepInterface |
||
| 4 | { |
||
| 5 | public function HideFromEveryone() |
||
| 9 | |||
| 10 | private static $defaults = array( |
||
|
|
|||
| 11 | 'CustomerCanEdit' => 0, |
||
| 12 | 'CustomerCanPay' => 0, |
||
| 13 | 'CustomerCanCancel' => 0, |
||
| 14 | 'Name' => 'Record Device Details', |
||
| 15 | 'Code' => 'RECORD_DEVICE_DETAILS', |
||
| 16 | 'ShowAsInProcessOrder' => 1, |
||
| 17 | ); |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The OrderStatusLog that is relevant to the particular step. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $relevantLogEntryClassName = 'OrderStatusLog_DeviceDetails'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Can run this step once any items have been submitted. |
||
| 28 | * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
||
| 29 | * should be able to run this function many times to check if the step is ready. |
||
| 30 | * |
||
| 31 | * @see Order::doNextStatus |
||
| 32 | * |
||
| 33 | * @param Order object |
||
| 34 | * |
||
| 35 | * @return bool - true if the current step is ready to be run... |
||
| 36 | **/ |
||
| 37 | public function initStep(Order $order) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * |
||
| 44 | * @param Order object |
||
| 45 | * |
||
| 46 | * @return bool - true if run correctly. |
||
| 47 | **/ |
||
| 48 | public function doStep(Order $order) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * go to next step if order has been submitted. |
||
| 64 | * |
||
| 65 | * @param Order $order |
||
| 66 | * |
||
| 67 | * @return OrderStep | Null (next step OrderStep) |
||
| 68 | **/ |
||
| 69 | public function nextStep(Order $order) |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * Explains the current order step. |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | protected function myDescription() |
||
| 84 | } |
||
| 85 |