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 |
||
9 | class OrderStep_SecurityCheck extends OrderStep implements OrderStepInterface |
||
|
|||
10 | { |
||
11 | private static $defaults = array( |
||
12 | 'CustomerCanEdit' => 0, |
||
13 | 'CustomerCanCancel' => 0, |
||
14 | 'CustomerCanPay' => 0, |
||
15 | 'Name' => 'Security Check for Order', |
||
16 | 'Code' => 'SECURITY_CHECK', |
||
17 | 'ShowAsInProcessOrder' => 1, |
||
18 | 'HideStepFromCustomer' => 1 |
||
19 | ); |
||
20 | |||
21 | /** |
||
22 | * The OrderStatusLog that is relevant to the particular step. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $relevantLogEntryClassName = 'OrderStatusLog_SecurityCheck'; |
||
27 | |||
28 | public function getCMSFields() |
||
34 | |||
35 | /** |
||
36 | *initStep: |
||
37 | * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt). |
||
38 | * should be able to run this function many times to check if the step is ready. |
||
39 | * |
||
40 | * @see Order::doNextStatus |
||
41 | * |
||
42 | * @param Order object |
||
43 | * |
||
44 | * @return bool - true if the current step is ready to be run... |
||
45 | **/ |
||
46 | public function initStep(Order $order) |
||
59 | |||
60 | private static $_passed = null; |
||
61 | |||
62 | /** |
||
63 | *doStep: |
||
64 | * should only be able to run this function once |
||
65 | * (init stops you from running it twice - in theory....) |
||
66 | * runs the actual step. |
||
67 | * |
||
68 | * @see Order::doNextStatus |
||
69 | * |
||
70 | * @param Order object |
||
71 | * |
||
72 | * @return bool - true if run correctly. |
||
73 | **/ |
||
74 | public function doStep(Order $order) |
||
84 | |||
85 | /** |
||
86 | *nextStep: |
||
87 | * returns the next step (after it checks if everything is in place for the next step to run...). |
||
88 | * |
||
89 | * @see Order::doNextStatus |
||
90 | * |
||
91 | * @param Order $order |
||
92 | * |
||
93 | * @return OrderStep | Null (next step OrderStep object) |
||
94 | **/ |
||
95 | public function nextStep(Order $order) |
||
103 | |||
104 | private static $_my_order = null; |
||
105 | |||
106 | /** |
||
107 | * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields. |
||
108 | * |
||
109 | * @param FieldList $fields |
||
110 | * @param Order $order |
||
111 | * |
||
112 | * @return FieldList |
||
113 | **/ |
||
114 | public function addOrderStepFields(FieldList $fields, Order $order) |
||
130 | |||
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 |
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.