| Conditions | 8 |
| Paths | 8 |
| Total Lines | 80 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 198 | private function _notificationsSettings() |
||
| 199 | { |
||
| 200 | global $txt, $modSettings; |
||
| 201 | |||
| 202 | Txt::load('Profile+UserNotifications'); |
||
| 203 | loadJavascriptFile('ext/jquery.multiselect.min.js'); |
||
| 204 | theme()->addInlineJavascript(' |
||
| 205 | $(\'.select_multiple\').multiselect({\'language_strings\': {\'Select all\': ' . JavaScriptEscape($txt['notify_select_all']) . '}}); |
||
| 206 | document.addEventListener("DOMContentLoaded", function() { |
||
| 207 | prepareNotificationOptions(); |
||
| 208 | });', true); |
||
| 209 | loadCSSFile('multiselect.css'); |
||
| 210 | |||
| 211 | // Mentions settings |
||
| 212 | $config_vars = [ |
||
| 213 | ['title', 'mentions_settings'], |
||
| 214 | ['check', 'mentions_enabled'], |
||
| 215 | ]; |
||
| 216 | |||
| 217 | $notification_methods = Notifications::instance()->getNotifiers(); |
||
| 218 | $notification_classes = getAvailableNotifications(); |
||
| 219 | $current_settings = unserialize($modSettings['notification_methods'], ['allowed_classes' => false]); |
||
| 220 | |||
| 221 | foreach ($notification_classes as $class) |
||
| 222 | { |
||
| 223 | // The canUse can be set by each notifier based on conditions, default is true; |
||
| 224 | /* @var $class AbstractNotificationMessage */ |
||
| 225 | if ($class::canUse() === false) |
||
| 226 | { |
||
| 227 | continue; |
||
| 228 | } |
||
| 229 | |||
| 230 | if ($class::hasHiddenInterface() === true) |
||
| 231 | { |
||
| 232 | $modSettings['hidden_notification_methods'][] = $class; |
||
| 233 | continue; |
||
| 234 | } |
||
| 235 | |||
| 236 | // Set up config enable/disable setting for all notifications. |
||
| 237 | $title = strtolower($class::getType()); |
||
| 238 | $config_vars[] = ['title', 'setting_' . $title]; |
||
| 239 | $config_vars[] = ['check', 'notifications[' . $title . '][enable]', 'text_label' => $txt['setting_notify_enable_this']]; |
||
| 240 | $modSettings['notifications[' . $title . '][enable]'] = !empty($current_settings[$title]); |
||
| 241 | $default_values = []; |
||
| 242 | $is_default = []; |
||
| 243 | |||
| 244 | // If it is enabled, show all the available ways, like email, notify, weekly ... |
||
| 245 | foreach (array_keys($notification_methods) as $method_name) |
||
| 246 | { |
||
| 247 | $method_name = strtolower($method_name); |
||
| 248 | |||
| 249 | // Are they excluding any, like don't let mailfail be allowed to send email! |
||
| 250 | if ($class::isNotAllowed($method_name)) |
||
| 251 | { |
||
| 252 | continue; |
||
| 253 | } |
||
| 254 | |||
| 255 | $config_vars[] = ['check', 'notifications[' . $title . '][' . $method_name . ']', 'text_label' => $txt['notify_' . $method_name]]; |
||
| 256 | $modSettings['notifications[' . $title . '][' . $method_name . ']'] = !empty($current_settings[$title][$method_name]); |
||
| 257 | $default_values[] = [$method_name, $txt['notify_' . $method_name]]; |
||
| 258 | if (empty($current_settings[$title][$method_name])) |
||
| 259 | { |
||
| 260 | continue; |
||
| 261 | } |
||
| 262 | |||
| 263 | if ((int) $current_settings[$title][$method_name] !== Notifications::DEFAULT_LEVEL) |
||
| 264 | { |
||
| 265 | continue; |
||
| 266 | } |
||
| 267 | |||
| 268 | $is_default[] = $method_name; |
||
| 269 | } |
||
| 270 | |||
| 271 | $config_vars[] = ['select', 'notifications[' . $title . '][default]', $default_values, 'text_label' => $txt['default_active'], 'multiple' => true, 'value' => $is_default]; |
||
| 272 | $modSettings['notifications[' . $title . '][default]'] = $is_default; |
||
| 273 | } |
||
| 274 | |||
| 275 | call_integration_hook('integrate_modify_mention_settings', [&$config_vars]); |
||
| 276 | |||
| 277 | return $config_vars; |
||
| 278 | } |
||
| 288 |