Conditions | 7 |
Paths | 64 |
Total Lines | 93 |
Code Lines | 37 |
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 declare(strict_types=1); |
||
15 | function xoops_module_update_smartfaq($module) |
||
16 | { |
||
17 | /* |
||
18 | // Load SmartDbUpdater from the SmartObject Framework if present |
||
19 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php'; |
||
20 | if (!file_exists($smartdbupdater)) { |
||
21 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartfaq/class/SmartobjectDbupdater.php'; |
||
22 | } |
||
23 | require_once $smartdbupdater; |
||
24 | */ |
||
25 | $dbupdater = new Smartfaq\SmartobjectDbupdater(); |
||
26 | /** @var Smartfaq\Helper $helper */ |
||
27 | $helper = Helper::getInstance(); |
||
28 | $helper->loadLanguage('smartdbupdater'); |
||
29 | |||
30 | ob_start(); |
||
31 | |||
32 | echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
||
33 | |||
34 | // Adding partialview field |
||
35 | $table = new Smartfaq\SmartDbTable('smartfaq_faq'); |
||
36 | if (!$table->fieldExists('partialview')) { |
||
37 | $table->addNewField('partialview', "tinyint(1) NOT NULL default '0'"); |
||
38 | } |
||
39 | |||
40 | // Changing categoryid type to int(11) |
||
41 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
42 | |||
43 | if (!$dbupdater->updateTable($table)) { |
||
44 | /** |
||
45 | * @todo trap the errors |
||
46 | */ |
||
47 | } |
||
48 | unset($table); |
||
49 | |||
50 | // Editing smartfaq_categories table |
||
51 | $table = new Smartfaq\SmartDbTable('smartfaq_categories'); |
||
52 | // Changing categoryid type to int(11) |
||
53 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
54 | |||
55 | // Changing parentid type to int(11) |
||
56 | $table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false); |
||
57 | |||
58 | if (!$dbupdater->updateTable($table)) { |
||
59 | /** |
||
60 | * @todo trap the errors |
||
61 | */ |
||
62 | } |
||
63 | unset($table); |
||
64 | |||
65 | // Editing smartfaq_answers table |
||
66 | $table = new Smartfaq\SmartDbTable('smartfaq_answers'); |
||
67 | // Changing categoryid type to int(11) |
||
68 | $table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false); |
||
69 | |||
70 | // Changing parentid type to int(11) |
||
71 | $table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false); |
||
72 | |||
73 | if (!$dbupdater->updateTable($table)) { |
||
74 | /** |
||
75 | * @todo trap the errors |
||
76 | */ |
||
77 | } |
||
78 | unset($table); |
||
79 | |||
80 | /** |
||
81 | * Check for items with categoryid=0 |
||
82 | */ // require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'; |
||
83 | /** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */ |
||
84 | $smartfaq_faqHandler = $answerHandler = Helper::getInstance()->getHandler('Faq'); |
||
|
|||
85 | /** @var \XoopsModules\Smartfaq\CategoryHandler $smartfaq_categoryHandler */ |
||
86 | $smartfaq_categoryHandler = $answerHandler = Helper::getInstance()->getHandler('Category'); |
||
87 | |||
88 | //find a valid categoryid |
||
89 | $categoriesObj = $smartfaq_categoryHandler->getCategories(1, 0, 0, 'weight', 'ASC', false); |
||
90 | if (count($categoriesObj) > 0) { |
||
91 | $categoryid = $categoriesObj[0]->getVar('categoryid'); |
||
92 | $criteria = new \CriteriaCompo(); |
||
93 | $criteria->add(new \Criteria('categoryid', 0)); |
||
94 | $smartfaq_faqHandler->updateAll('categoryid', $categoryid, $criteria); |
||
95 | echo ' Cleaning up questions with categoryid=0<br>'; |
||
96 | } |
||
97 | |||
98 | echo '</code>'; |
||
99 | |||
100 | $feedback = ob_get_clean(); |
||
101 | if (method_exists($module, 'setMessage')) { |
||
102 | $module->setMessage($feedback); |
||
103 | } else { |
||
104 | echo $feedback; |
||
105 | } |
||
106 | |||
107 | return true; |
||
108 | } |
||
129 |