| Conditions | 21 |
| Paths | 104 |
| Total Lines | 120 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 462 |
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 |
||
| 67 | public function display() |
||
| 68 | { |
||
| 69 | global $mod_strings, $app_strings; |
||
| 70 | |||
| 71 | $admin = new Administration(); |
||
| 72 | $admin->retrieveSettings(); |
||
| 73 | |||
| 74 | // Handle posts |
||
| 75 | if (!empty($_REQUEST['process'])) { |
||
| 76 | // Check the cleanup logic hook, make sure it is still there |
||
| 77 | check_logic_hook_file('Users', 'after_login', array(1, 'SugarFeed old feed entry remover', 'modules/SugarFeed/SugarFeedFlush.php', 'SugarFeedFlush', 'flushStaleEntries')); |
||
| 78 | |||
| 79 | // We have data posted |
||
| 80 | if ($_REQUEST['process'] == 'true') { |
||
| 81 | // They want us to process it, the false will just fall outside of this statement |
||
| 82 | if ($_REQUEST['feed_enable'] == '1') { |
||
| 83 | // The feed is enabled, pay attention to what categories should be enabled or disabled |
||
| 84 | |||
| 85 | $db = DBManagerFactory::getInstance(); |
||
| 86 | $ret = $db->query("SELECT * FROM config WHERE category = 'sugarfeed' AND name LIKE 'module_%'"); |
||
| 87 | $current_modules = array(); |
||
| 88 | while ($row = $db->fetchByAssoc($ret)) { |
||
| 89 | $current_modules[$row['name']] = $row['value']; |
||
| 90 | } |
||
| 91 | |||
| 92 | $active_modules = $_REQUEST['modules']; |
||
| 93 | if (!is_array($active_modules)) { |
||
| 94 | $active_modules = array(); |
||
| 95 | } |
||
| 96 | |||
| 97 | foreach ($active_modules as $name => $is_active) { |
||
| 98 | $module = substr($name, 7); |
||
| 99 | |||
| 100 | if ($is_active == '1') { |
||
| 101 | // They are activating something that was disabled before |
||
| 102 | SugarFeed::activateModuleFeed($module); |
||
| 103 | } else { |
||
| 104 | // They are disabling something that was active before |
||
| 105 | SugarFeed::disableModuleFeed($module); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $admin->saveSetting('sugarfeed', 'enabled', '1'); |
||
| 110 | } else { |
||
| 111 | $admin->saveSetting('sugarfeed', 'enabled', '0'); |
||
| 112 | // Now we need to remove all of the logic hooks, so they don't continue to run |
||
| 113 | // We also need to leave the database alone, so they can enable/disable modules with the system disabled |
||
| 114 | $modulesWithFeeds = SugarFeed::getAllFeedModules(); |
||
| 115 | |||
| 116 | foreach ($modulesWithFeeds as $currFeedModule) { |
||
| 117 | SugarFeed::disableModuleFeed($currFeedModule, FALSE); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | $admin->retrieveSettings(FALSE, TRUE); |
||
| 122 | SugarFeed::flushBackendCache(); |
||
| 123 | } else if ($_REQUEST['process'] == 'deleteRecords') { |
||
| 124 | if (!isset($db)) { |
||
|
|
|||
| 125 | $db = DBManagerFactory::getInstance(); |
||
| 126 | } |
||
| 127 | $db->query("UPDATE sugarfeed SET deleted = '1'"); |
||
| 128 | echo(translate('LBL_RECORDS_DELETED', 'SugarFeed')); |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | if ($_REQUEST['process'] == 'true' || $_REQUEST['process'] == 'false') { |
||
| 133 | header('Location: index.php?module=Administration&action=index'); |
||
| 134 | return; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | $sugar_smarty = new Sugar_Smarty(); |
||
| 139 | $sugar_smarty->assign('mod', $mod_strings); |
||
| 140 | $sugar_smarty->assign('app', $app_strings); |
||
| 141 | |||
| 142 | if (isset($admin->settings['sugarfeed_enabled']) && $admin->settings['sugarfeed_enabled'] == '1') { |
||
| 143 | $sugar_smarty->assign('enabled_checkbox', 'checked'); |
||
| 144 | } |
||
| 145 | |||
| 146 | $possible_feeds = SugarFeed::getAllFeedModules(); |
||
| 147 | $possible_feeds['facebook'] = 'Facebook'; |
||
| 148 | $possible_feeds['twitter'] = 'Twitter'; |
||
| 149 | $module_list = array(); |
||
| 150 | $userFeedEnabled = 0; |
||
| 151 | foreach ($possible_feeds as $module) { |
||
| 152 | $currModule = array(); |
||
| 153 | if (isset($admin->settings['sugarfeed_module_' . $module]) && $admin->settings['sugarfeed_module_' . $module] == '1') { |
||
| 154 | $currModule['enabled'] = 1; |
||
| 155 | } else { |
||
| 156 | $currModule['enabled'] = 0; |
||
| 157 | } |
||
| 158 | |||
| 159 | $currModule['module'] = $module; |
||
| 160 | if ($module == 'UserFeed') { |
||
| 161 | // Fake module, need to handle specially |
||
| 162 | $userFeedEnabled = $currModule['enabled']; |
||
| 163 | continue; |
||
| 164 | } elseif ($module == 'Facebook' || $module == 'Twitter') { |
||
| 165 | |||
| 166 | $currModule['label'] = $module; |
||
| 167 | |||
| 168 | } else { |
||
| 169 | $currModule['label'] = $GLOBALS['app_list_strings']['moduleList'][$module]; |
||
| 170 | } |
||
| 171 | |||
| 172 | $module_list[] = $currModule; |
||
| 173 | } |
||
| 174 | $sugar_smarty->assign('module_list', $module_list); |
||
| 175 | $sugar_smarty->assign('user_feed_enabled', $userFeedEnabled); |
||
| 176 | |||
| 177 | echo getClassicModuleTitle( |
||
| 178 | "Administration", |
||
| 179 | array( |
||
| 180 | "<a href='index.php?module=Administration&action=index'>" . translate('LBL_MODULE_NAME', 'Administration') . "</a>", |
||
| 181 | $mod_strings['LBL_MODULE_NAME'], |
||
| 182 | ), |
||
| 183 | false |
||
| 184 | ); |
||
| 185 | $sugar_smarty->display('modules/SugarFeed/tpls/AdminSettings.tpl'); |
||
| 186 | } |
||
| 187 | } |
||
| 189 |
This check marks calls to
isset(...)orempty(...)that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.