| Total Complexity | 61 |
| Total Lines | 413 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CheckoutWizard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CheckoutWizard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class CheckoutWizard extends ZervWizard |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * checkoutwizard constructor. |
||
| 11 | */ |
||
| 12 | public function __construct() |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @todo change access to fields using PedigreeFields |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | public function prepareFieldname() |
||
| 44 | { |
||
| 45 | global $field; |
||
| 46 | if (0 == !$field) { |
||
| 47 | // field already exists (editing mode) |
||
| 48 | |||
| 49 | $sql = 'SELECT * from ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' WHERE Id=' . $field; |
||
| 50 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 51 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 52 | $name = $row['fieldname']; |
||
| 53 | $fieldexplanation = $row['fieldexplanation']; |
||
| 54 | $fieldtype = $row['fieldtype']; |
||
| 55 | } |
||
| 56 | $this->setValue('name', $name); |
||
| 57 | $this->setValue('explain', $fieldexplanation); |
||
| 58 | //set the fieldtype because we wont allow it to be edited |
||
| 59 | $this->setValue('fieldtype', $fieldtype); |
||
| 60 | } |
||
| 61 | $this->setValue('field', $field); //is it a new field or are we editing a field |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param $form |
||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | public function processFieldname(&$form) |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Setup this class' fieldtype array |
||
| 90 | * @return void |
||
| 91 | */ |
||
| 92 | public function prepareFieldtype() |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param $form |
||
| 104 | * |
||
| 105 | * @return bool |
||
| 106 | */ |
||
| 107 | public function processFieldtype($form) |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param $form |
||
| 118 | * |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public function processLookup($form) |
||
| 122 | { |
||
| 123 | $fc = $this->coalesce($form['fc']); |
||
| 124 | $this->setValue('fc', $fc); |
||
| 125 | $lookup = $this->coalesce($form['lookup' . $fc]); |
||
| 126 | $lookupid = $this->coalesce($form['id' . $fc]); |
||
| 127 | if (strlen($lookup) > 0) { |
||
| 128 | $this->setValue('lookup' . $fc, $lookup); |
||
| 129 | $this->setValue('id' . $fc, $lookupid); |
||
| 130 | } |
||
| 131 | $lastlookup = $this->getValue('lookup' . $fc); |
||
| 132 | if ($lastlookup == '') { |
||
| 133 | $this->setValue('fc', $fc - 1); |
||
| 134 | } |
||
| 135 | |||
| 136 | for ($i = 0; $i < $fc; ++$i) { |
||
| 137 | $radioarray[] = array('id' => $this->getValue('id' . ($i + 1)), 'value' => $this->getValue('lookup' . ($i + 1))); |
||
| 138 | } |
||
| 139 | //print_r($radioarray); die(); |
||
| 140 | $this->setValue('radioarray', $radioarray); |
||
| 141 | |||
| 142 | return !$this->isError(); |
||
| 143 | // |
||
| 144 | } |
||
| 145 | |||
| 146 | public function prepareSettings() |
||
| 147 | { |
||
| 148 | if (0 == !$this->getValue('field')) { |
||
| 149 | // field allready exists (editing mode) |
||
| 150 | |||
| 151 | { |
||
| 152 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . " WHERE Id='" . $this->getValue('field') . "'"; |
||
| 153 | } |
||
| 154 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 155 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 156 | $hs = $row['hassearch']; |
||
| 157 | if ('1' == $hs) { |
||
| 158 | $this->setValue('hassearch', 'hassearch'); |
||
| 159 | } |
||
| 160 | $vip = $row['viewinpedigree']; |
||
| 161 | if ('1' == $vip) { |
||
| 162 | $this->setValue('viewinpedigree', 'viewinpedigree'); |
||
| 163 | } |
||
| 164 | $via = $row['viewinadvanced']; |
||
| 165 | if ('1' == $via) { |
||
| 166 | $this->setValue('viewinadvanced', 'viewinadvanced'); |
||
| 167 | } |
||
| 168 | $vipie = $row['viewinpie']; |
||
| 169 | if ('1' == $vipie) { |
||
| 170 | $this->setValue('viewinpie', 'viewinpie'); |
||
| 171 | } |
||
| 172 | $vil = $row['viewinlist']; |
||
| 173 | if ('1' == $vil) { |
||
| 174 | $this->setValue('viewinlist', 'viewinlist'); |
||
| 175 | } |
||
| 176 | $lit = $row['litter']; |
||
| 177 | if ('1' == $lit) { |
||
| 178 | $this->setValue('litter', 'litter'); |
||
| 179 | } |
||
| 180 | $glit = $row['generallitter']; |
||
| 181 | if ('1' == $glit) { |
||
| 182 | $this->setValue('generallitter', 'generallitter'); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @param $form |
||
| 190 | * |
||
| 191 | * @return bool |
||
| 192 | */ |
||
| 193 | public function processSettings($form) |
||
| 194 | { |
||
| 195 | $this->setValue('hassearch', $this->coalesce($form['hasSearch'])); |
||
| 196 | $this->setValue('viewinpedigree', $this->coalesce($form['viewInPedigree'])); |
||
| 197 | $this->setValue('viewinadvanced', $this->coalesce($form['viewInAdvanced'])); |
||
| 198 | $this->setValue('viewinpie', $this->coalesce($form['viewInPie'])); |
||
| 199 | $this->setValue('viewinlist', $this->coalesce($form['viewInList'])); |
||
| 200 | $this->setValue('litter', $this->coalesce($form['litter'])); |
||
| 201 | $this->setValue('generallitter', $this->coalesce($form['generalLitter'])); |
||
| 202 | |||
| 203 | //if both litter and general litter are set; unset generallitter |
||
| 204 | if (('litter' === $this->getValue('litter')) && ('generallitter' === $this->getValue('generallitter'))) { |
||
| 205 | $this->setValue('generallitter', 0); |
||
| 206 | } |
||
| 207 | |||
| 208 | return !$this->isError(); |
||
| 209 | } |
||
| 210 | |||
| 211 | public function prepareSearch() |
||
| 212 | { |
||
| 213 | if (0 == !$this->getValue('field')) { |
||
| 214 | // field allready exists (editing mode) |
||
| 215 | |||
| 216 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' WHERE Id=' . $this->getValue('field'); |
||
| 217 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 218 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 219 | if ('hasearch' === $this->getValue('hassearch')) { |
||
| 220 | $searchname = $row['searchname']; |
||
| 221 | $this->setValue('searchname', $searchname); |
||
| 222 | $searchexplain = $row['searchexplanation']; |
||
| 223 | $this->setValue('searchexplain', $searchexplain); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param $form |
||
| 231 | * |
||
| 232 | * @return bool |
||
| 233 | * @todo move language strings to language files |
||
| 234 | */ |
||
| 235 | public function processSearch($form) |
||
| 236 | { |
||
| 237 | $searchname = $this->coalesce($form['searchname']); |
||
| 238 | if (strlen($searchname) > 0) { |
||
| 239 | $this->setValue('searchname', $searchname); |
||
| 240 | } else { |
||
| 241 | $this->addError('searchname', 'Please enter the searchname'); |
||
| 242 | } |
||
| 243 | |||
| 244 | $fieldexplanation = $this->coalesce($form['searchexplain']); |
||
| 245 | if (strlen($fieldexplanation) > 0) { |
||
| 246 | $this->setValue('searchexplain', $fieldexplanation); |
||
| 247 | } else { |
||
| 248 | $this->addError('searchexplain', 'Please enter the search explanation for this field'); |
||
| 249 | } |
||
| 250 | |||
| 251 | return !$this->isError(); |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @return void |
||
| 256 | */ |
||
| 257 | public function prepareDefaultvalue() |
||
| 277 | } |
||
| 278 | } |
||
| 279 | } |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param $form |
||
| 284 | * |
||
| 285 | * @return bool |
||
| 286 | * @todo move language string to language file |
||
| 287 | */ |
||
| 288 | public function processDefaultValue($form) |
||
| 289 | { |
||
| 290 | $defaultvalue = $this->coalesce($form['defaultvalue']); |
||
| 291 | if (strlen($defaultvalue) >= 0) { |
||
| 292 | $this->setValue('defaultvalue', $defaultvalue); |
||
| 293 | } else { |
||
| 294 | $this->addError('defaultvalue', 'Please enter a defaultvalue'); |
||
| 295 | } |
||
| 296 | |||
| 297 | return !$this->isError(); |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param $form |
||
| 302 | * |
||
| 303 | * @return bool |
||
| 304 | */ |
||
| 305 | public function processConfirm($form) |
||
| 306 | { |
||
| 307 | return !$this->isError(); |
||
| 308 | } |
||
| 309 | |||
| 310 | public function completeCallback() |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Miscellaneous utility functions |
||
| 411 | * |
||
| 412 | * @param $email |
||
| 413 | * |
||
| 414 | * @return int |
||
| 415 | */ |
||
| 416 | |||
| 417 | public function isValidEmail($email) |
||
| 420 | } |
||
| 421 | } |
||
| 422 |