Conditions | 9 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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); |
||
32 | function xoops_module_update_waiting($module, $version) |
||
33 | { |
||
34 | return true; // force return - following code is really only needed for XOOPS < 2.3 |
||
35 | // Keep Block option values when update (by nobunobu) |
||
36 | $mid = $module->mid(); |
||
37 | if ($mid) { |
||
38 | /** @var \XoopsConfigHandler $configHandler */ |
||
39 | $configHandler = xoops_getHandler('config'); |
||
40 | $waitingModuleConfig = $configHandler->getConfigsByCat(0, $mid); |
||
41 | |||
42 | $count = count($waitingModuleConfig['blocks']); |
||
43 | |||
44 | /** @var \XoopsBlockHandler $blockHandler */ |
||
45 | $blockHandler = xoops_getHandler('block'); |
||
46 | $criteria = new \CriteriaCompo(); |
||
47 | $criteria->add(new \Criteria('mid', $mid)); |
||
48 | $criteria->add(new \Criteria('block_type', 'D')); |
||
49 | $criteria->add(new \Criteria('func_num', $count, '>')); |
||
50 | $blockObjs = $blockHandler->getAll($criteria); |
||
51 | |||
52 | foreach ($blockObjs as $blockObj) { |
||
53 | $local_msgs[] = "Non Defined Block <b>{$fblock['name']}</b> will be deleted"; |
||
54 | $success = $blockHandler->delete($blockObj); // remove the invalid block |
||
55 | } |
||
56 | |||
57 | $fieldsArray = ['func_num', 'name', 'options']; |
||
58 | $criteria = new \CriteriaCompo(); |
||
59 | $criteria->add(new \Criteria('mid', $mid)); |
||
60 | // $criteria->add(new \Criteria('func_num', $i)); |
||
61 | $criteria->add(new \Criteria('show_func'), addslashes($waitingModuleConfig['blocks'][$i]['show_func'])); |
||
62 | $criteria->add(new \Criteria('func_file', addslashes($waitingModuleConfig['blocks'][$i]['file']))); |
||
63 | $fblockObjs = $blockHandler->getObjects($criteria); |
||
64 | foreach ($fblockObjs as $fblockObj) { |
||
65 | if (!empty($fblockObj->options())) { |
||
66 | $old_vals = explode('|', $fblockObj->getVar('options')); |
||
67 | $def_vals = explode('|', $modversion['blocks'][$fblockObj->getVar('func_num')]['options']); |
||
68 | if (count($old_vals) == count($def_vals)) { |
||
69 | $modversion['blocks'][$fblock->getVar('func_num')]['options'] = $fblockObj->getVar('options'); |
||
70 | $local_msgs[] = "Option's values of the block <b>" . $fblockObj->getVar('name') . '</b> will be kept. (value = <b>' . $fblockObj->getVar('options') . '</b>)'; |
||
71 | } elseif (count($old_vals) < count($def_vals)) { |
||
72 | $def_vals = array_merge($old_vals, $def_vals); //merges prev. values with new - older are preserved |
||
73 | $modversion['blocks'][$fblockObj->getVar('func_num')]['options'] = implode('|', $def_vals); |
||
74 | $local_msgs[] = "Option's values of the block " |
||
75 | . '<b>' |
||
76 | . $fblockObj->getVar('name') |
||
77 | . '</b> ' |
||
78 | . 'will be kept and new option(s) are added. (value = ' |
||
79 | . '<b>' |
||
80 | . $waitingModuleConfig['blocks'][$fblockObj->getVar('options')] |
||
81 | . '</b>)'; |
||
82 | } else { |
||
83 | $local_msgs[] = "Option's values of the block " . '<b>' . $fblockObj->getVar('name') . '</b> ' . 'will be reset to the default, because of some decrease of options. (value = ' . '<b>' . $waitingModuleConfig['blocks'][$fblockObj->getVar('func_num')]['options'] . '</b>)'; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | global $msgs, $myblocksadmin_parsed_updateblock; |
||
90 | if (!empty($msgs) && empty($myblocksadmin_parsed_updateblock)) { |
||
91 | $msgs = array_merge($msgs, $local_msgs); |
||
92 | $myblocksadmin_parsed_updateblock = true; |
||
93 | } |
||
94 | |||
95 | return true; //@todo: for now force success - eventually send 'actual' results |
||
96 | } |
||
97 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.