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_WhitelistCustomer extends OrderStep implements OrderStepInterface |
||
|
|
|||
| 4 | { |
||
| 5 | private static $defaults = array( |
||
| 6 | 'CustomerCanEdit' => 0, |
||
| 7 | 'CustomerCanCancel' => 0, |
||
| 8 | 'CustomerCanPay' => 0, |
||
| 9 | 'Name' => 'Whitelist Customer', |
||
| 10 | 'Code' => 'WHITELIST_CUSTOMER', |
||
| 11 | 'ShowAsInProcessOrder' => 1, |
||
| 12 | 'HideStepFromCustomer' => 1 |
||
| 13 | ); |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The OrderStatusLog that is relevant to the particular step. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $relevantLogEntryClassName = 'OrderStatusLog_WhitelistCustomer'; |
||
| 21 | |||
| 22 | public function getCMSFields() |
||
| 28 | |||
| 29 | /** |
||
| 30 | * initStep: |
||
| 31 | * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
||
| 32 | * should be able to run this function many times to check if the step is ready. |
||
| 33 | * |
||
| 34 | * @see Order::doNextStatus |
||
| 35 | * |
||
| 36 | * @param Order object |
||
| 37 | * |
||
| 38 | * @return bool - true if the current step is ready to be run... |
||
| 39 | **/ |
||
| 40 | public function initStep(Order $order) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * |
||
| 47 | * |
||
| 48 | * @var null | bool |
||
| 49 | */ |
||
| 50 | private $_completed = null; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * doStep: |
||
| 54 | * should only be able to run this function once |
||
| 55 | * (init stops you from running it twice - in theory....) |
||
| 56 | * runs the actual step. |
||
| 57 | * |
||
| 58 | * @see Order::doNextStatus |
||
| 59 | * |
||
| 60 | * @param Order object |
||
| 61 | * |
||
| 62 | * @return bool - true if run correctly. |
||
| 63 | **/ |
||
| 64 | public function doStep(Order $order) |
||
| 81 | |||
| 82 | /** |
||
| 83 | *nextStep: |
||
| 84 | * returns the next step (after it checks if everything is in place for the next step to run...). |
||
| 85 | * |
||
| 86 | * @see Order::doNextStatus |
||
| 87 | * |
||
| 88 | * @param Order $order |
||
| 89 | * |
||
| 90 | * @return OrderStep | Null (next step OrderStep object) |
||
| 91 | **/ |
||
| 92 | public function nextStep(Order $order) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * For some ordersteps this returns true... |
||
| 103 | * |
||
| 104 | * @return bool |
||
| 105 | **/ |
||
| 106 | protected function hasCustomerMessage() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Explains the current order step. |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | protected function myDescription() |
||
| 120 | |||
| 121 | public function HideFromEveryone() |
||
| 125 | } |
||
| 126 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.