Conditions | 7 |
Paths | 64 |
Total Lines | 92 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | function xoops_module_update_smartfaq($module) |
||
17 | { |
||
18 | /* |
||
19 | // Load SmartDbUpdater from the SmartObject Framework if present |
||
20 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php'; |
||
21 | if (!file_exists($smartdbupdater)) { |
||
22 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartfaq/class/SmartobjectDbupdater.php'; |
||
23 | } |
||
24 | require_once $smartdbupdater; |
||
25 | */ |
||
26 | $dbupdater = new \XoopsModules\Smartfaq\SmartobjectDbupdater(); |
||
27 | |||
28 | ob_start(); |
||
29 | |||
30 | echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
||
31 | |||
32 | // Adding partialview field |
||
33 | $table = new Smartfaq\SmartDbTable('smartfaq_faq'); |
||
34 | if (!$table->fieldExists('partialview')) { |
||
35 | $table->addNewField('partialview', "tinyint(1) NOT NULL default '0'"); |
||
36 | } |
||
37 | |||
38 | // Changing categoryid type to int(11) |
||
39 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
40 | |||
41 | if (!$dbupdater->updateTable($table)) { |
||
42 | /** |
||
43 | * @todo trap the errors |
||
44 | */ |
||
45 | } |
||
46 | unset($table); |
||
47 | |||
48 | // Editing smartfaq_categories table |
||
49 | $table = new Smartfaq\SmartDbTable('smartfaq_categories'); |
||
50 | // Changing categoryid type to int(11) |
||
51 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
52 | |||
53 | // Changing parentid type to int(11) |
||
54 | $table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false); |
||
55 | |||
56 | if (!$dbupdater->updateTable($table)) { |
||
57 | /** |
||
58 | * @todo trap the errors |
||
59 | */ |
||
60 | } |
||
61 | unset($table); |
||
62 | |||
63 | // Editing smartfaq_answers table |
||
64 | $table = new Smartfaq\SmartDbTable('smartfaq_answers'); |
||
65 | // Changing categoryid type to int(11) |
||
66 | $table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false); |
||
67 | |||
68 | // Changing parentid type to int(11) |
||
69 | $table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false); |
||
70 | |||
71 | if (!$dbupdater->updateTable($table)) { |
||
72 | /** |
||
73 | * @todo trap the errors |
||
74 | */ |
||
75 | } |
||
76 | unset($table); |
||
77 | |||
78 | /** |
||
79 | * Check for items with categoryid=0 |
||
80 | */ |
||
81 | // require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
||
82 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
83 | $smartfaq_faqHandler = $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq'); |
||
|
|||
84 | /** @var \XoopsModules\Smartfaq\CategoryHandler $smartfaq_categoryHandler */ |
||
85 | $smartfaq_categoryHandler = $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category'); |
||
86 | |||
87 | //find a valid categoryid |
||
88 | $categoriesObj = $smartfaq_categoryHandler->getCategories(1, 0, 0, 'weight', 'ASC', false); |
||
89 | if (count($categoriesObj) > 0) { |
||
90 | $categoryid = $categoriesObj[0]->getVar('categoryid'); |
||
91 | $criteria = new \CriteriaCompo(); |
||
92 | $criteria->add(new \Criteria('categoryid', 0)); |
||
93 | $smartfaq_faqHandler->updateAll('categoryid', $categoryid, $criteria); |
||
94 | echo ' Cleaning up questions with categoryid=0<br>'; |
||
95 | } |
||
96 | |||
97 | echo '</code>'; |
||
98 | |||
99 | $feedback = ob_get_clean(); |
||
100 | if (method_exists($module, 'setMessage')) { |
||
101 | $module->setMessage($feedback); |
||
102 | } else { |
||
103 | echo $feedback; |
||
104 | } |
||
105 | |||
106 | return true; |
||
107 | } |
||
108 | |||
128 |