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 |
||
8 | class OrderStep_FraudCheck extends OrderStep implements OrderStepInterface |
||
9 | { |
||
10 | public static $db = [ |
||
11 | 'MinOrderValue' => 'Int', |
||
12 | 'MinFraudService' => 'Enum("Score,Insights","Score")' |
||
13 | ]; |
||
14 | |||
15 | private static $defaults = [ |
||
|
|||
16 | 'CustomerCanEdit' => 0, |
||
17 | 'CustomerCanCancel' => 0, |
||
18 | 'CustomerCanPay' => 0, |
||
19 | 'Name' => 'Fraud Check for Order', |
||
20 | 'Code' => 'FRAUD_CHECK', |
||
21 | 'ShowAsInProcessOrder' => 1, |
||
22 | 'HideStepFromCustomer' => 1 |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * The OrderStatusLog that is relevant to the particular step. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $relevantLogEntryClassName = 'OrderStatusLog_MinFraudStatusLog'; |
||
31 | |||
32 | public function getCMSFields() |
||
66 | |||
67 | /** |
||
68 | *initStep: |
||
69 | * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
||
70 | * should be able to run this function many times to check if the step is ready. |
||
71 | * |
||
72 | * @see Order::doNextStatus |
||
73 | * |
||
74 | * @param Order object |
||
75 | * |
||
76 | * @return bool - true if the current step is ready to be run... |
||
77 | **/ |
||
78 | public function initStep(Order $order) |
||
82 | |||
83 | |||
84 | /** |
||
85 | *doStep: |
||
86 | * should only be able to run this function once |
||
87 | * (init stops you from running it twice - in theory....) |
||
88 | * runs the actual step. |
||
89 | * |
||
90 | * @see Order::doNextStatus |
||
91 | * |
||
92 | * @param Order object |
||
93 | * |
||
94 | * @return bool - true if run correctly. |
||
95 | **/ |
||
96 | public function doStep(Order $order) |
||
116 | |||
117 | /** |
||
118 | *nextStep: |
||
119 | * returns the next step (after it checks if everything is in place for the next step to run...). |
||
120 | * |
||
121 | * @see Order::doNextStatus |
||
122 | * |
||
123 | * @param Order $order |
||
124 | * |
||
125 | * @return OrderStep | Null (next step OrderStep object) |
||
126 | **/ |
||
127 | public function nextStep(Order $order) |
||
131 | |||
132 | /** |
||
133 | * For some ordersteps this returns true... |
||
134 | * |
||
135 | * @return bool |
||
136 | **/ |
||
137 | protected function hasCustomerMessage() |
||
141 | |||
142 | /** |
||
143 | * Explains the current order step. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | protected function myDescription() |
||
151 | } |
||
152 |