| Conditions | 13 |
| Paths | 72 |
| Total Lines | 36 |
| Code Lines | 20 |
| 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 |
||
| 90 | public function handleModuleConfigChanges(ConfigClass $configClassObj, array $moduleRecord):void |
||
| 91 | { |
||
| 92 | // Reconfigure fail2ban and restart iptables |
||
| 93 | if (method_exists($configClassObj, SystemConfigInterface::GENERATE_FAIL2BAN_JAILS) |
||
| 94 | && !empty(call_user_func([$configClassObj, SystemConfigInterface::GENERATE_FAIL2BAN_JAILS]))) { |
||
| 95 | WorkerModelsEvents::invokeAction(ReloadFail2BanConfAction::class, [], 50); |
||
| 96 | } |
||
| 97 | |||
| 98 | // Refresh Nginx conf if the module has any locations |
||
| 99 | if (method_exists($configClassObj, SystemConfigInterface::CREATE_NGINX_LOCATIONS) |
||
| 100 | && !empty(call_user_func([$configClassObj, SystemConfigInterface::CREATE_NGINX_LOCATIONS]))) { |
||
| 101 | WorkerModelsEvents::invokeAction(ReloadNginxConfAction::class, [], 50); |
||
| 102 | } |
||
| 103 | |||
| 104 | // Refresh crontab rules if module has any for it |
||
| 105 | if (method_exists($configClassObj, SystemConfigInterface::CREATE_CRON_TASKS)) { |
||
| 106 | $tasks = []; |
||
| 107 | call_user_func_array([$configClassObj, SystemConfigInterface::CREATE_CRON_TASKS], [&$tasks]); |
||
| 108 | if (!empty($tasks)) { |
||
| 109 | WorkerModelsEvents::invokeAction(ReloadCrondAction::class, [], 50); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | // Reconfigure asterisk manager interface |
||
| 114 | if (method_exists($configClassObj, AsteriskConfigInterface::GENERATE_MANAGER_CONF) |
||
| 115 | && !empty(call_user_func([$configClassObj, AsteriskConfigInterface::GENERATE_MANAGER_CONF]))) { |
||
| 116 | WorkerModelsEvents::invokeAction(ReloadManagerAction::class, [], 50); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Hook modules AFTER_ methods |
||
| 120 | if ($moduleRecord['disabled'] === '1' |
||
| 121 | && method_exists($configClassObj, SystemConfigInterface::ON_AFTER_MODULE_DISABLE)) { |
||
| 122 | call_user_func([$configClassObj, SystemConfigInterface::ON_AFTER_MODULE_DISABLE]); |
||
| 123 | } elseif ($moduleRecord['disabled'] === '0' |
||
| 124 | && method_exists($configClassObj, SystemConfigInterface::ON_AFTER_MODULE_ENABLE)) { |
||
| 125 | call_user_func([$configClassObj, SystemConfigInterface::ON_AFTER_MODULE_ENABLE]); |
||
| 126 | } |
||
| 128 | } |