Conditions | 8 |
Paths | 128 |
Total Lines | 89 |
Code Lines | 41 |
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 |
||
9 | function xoops_module_update_smartfaq($module) |
||
10 | { |
||
11 | // Load SmartDbUpdater from the SmartObject Framework if present |
||
12 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartobject/class/smartdbupdater.php'; |
||
13 | if (!file_exists($smartdbupdater)) { |
||
14 | $smartdbupdater = XOOPS_ROOT_PATH . '/modules/smartfaq/class/smartdbupdater.php'; |
||
15 | } |
||
16 | include_once($smartdbupdater); |
||
17 | |||
18 | $dbupdater = new SmartobjectDbupdater(); |
||
19 | |||
20 | ob_start(); |
||
21 | |||
22 | echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />'; |
||
23 | |||
24 | // Adding partialview field |
||
25 | $table = new SmartDbTable('smartfaq_faq'); |
||
26 | if (!$table->fieldExists('partialview')) { |
||
27 | $table->addNewField('partialview', "tinyint(1) NOT NULL default '0'"); |
||
28 | } |
||
29 | |||
30 | // Changing categoryid type to int(11) |
||
31 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
32 | |||
33 | if (!$dbupdater->updateTable($table)) { |
||
34 | /** |
||
35 | * @todo trap the errors |
||
36 | */ |
||
37 | } |
||
38 | unset($table); |
||
39 | |||
40 | // Editing smartfaq_categories table |
||
41 | $table = new SmartDbTable('smartfaq_categories'); |
||
42 | // Changing categoryid type to int(11) |
||
43 | $table->addAlteredField('categoryid', "int(11) NOT NULL default '0'", false); |
||
44 | |||
45 | // Changing parentid type to int(11) |
||
46 | $table->addAlteredField('parentid', "int(11) NOT NULL default '0'", false); |
||
47 | |||
48 | if (!$dbupdater->updateTable($table)) { |
||
49 | /** |
||
50 | * @todo trap the errors |
||
51 | */ |
||
52 | } |
||
53 | unset($table); |
||
54 | |||
55 | // Editing smartfaq_answers table |
||
56 | $table = new SmartDbTable('smartfaq_answers'); |
||
57 | // Changing categoryid type to int(11) |
||
58 | $table->addAlteredField('answerid', "int(11) NOT NULL default '0'", false); |
||
59 | |||
60 | // Changing parentid type to int(11) |
||
61 | $table->addAlteredField('faqid', "int(11) NOT NULL default '0'", false); |
||
62 | |||
63 | if (!$dbupdater->updateTable($table)) { |
||
64 | /** |
||
65 | * @todo trap the errors |
||
66 | */ |
||
67 | } |
||
68 | unset($table); |
||
69 | |||
70 | /** |
||
71 | * Check for items with categoryid=0 |
||
72 | */ |
||
73 | include_once(XOOPS_ROOT_PATH . '/modules/smartfaq/include/functions.php'); |
||
74 | $smartfaq_faqHandler = $answerHandler = sf_gethandler('faq'); |
||
75 | $smartfaq_categoryHandler = $answerHandler = sf_gethandler('category'); |
||
76 | |||
77 | //find a valid categoryid |
||
78 | $categoriesObj = $smartfaq_categoryHandler->getCategories(1, 0, 0, 'weight', 'ASC', false); |
||
79 | if (count($categoriesObj) > 0) { |
||
80 | $categoryid = $categoriesObj[0]->getVar('categoryid'); |
||
81 | $criteria = new CriteriaCompo(); |
||
82 | $criteria->add(new Criteria('categoryid', 0)); |
||
83 | $smartfaq_faqHandler->updateAll('categoryid', $categoryid, $criteria); |
||
84 | echo ' Cleaning up questions with categoryid=0<br />'; |
||
85 | } |
||
86 | |||
87 | echo '</code>'; |
||
88 | |||
89 | $feedback = ob_get_clean(); |
||
90 | if (method_exists($module, 'setMessage')) { |
||
91 | $module->setMessage($feedback); |
||
92 | } else { |
||
93 | echo $feedback; |
||
94 | } |
||
95 | |||
96 | return true; |
||
97 | } |
||
98 | |||
118 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.