| Conditions | 6 |
| Paths | 32 |
| Total Lines | 51 |
| Code Lines | 32 |
| 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 |
||
| 37 | private function generateConfig($boot = true): void |
||
| 38 | { |
||
| 39 | $additionalModules = $this->di->getShared('pbxConfModules'); |
||
| 40 | $mast_have = []; |
||
| 41 | |||
| 42 | if (Util::isSystemctl()) { |
||
| 43 | $mast_have[] = "SHELL=/bin/sh\n"; |
||
| 44 | $mast_have[] = "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n\n"; |
||
| 45 | $cron_filename = '/etc/cron.d/mikopbx'; |
||
| 46 | $cron_user = 'root '; |
||
| 47 | } else { |
||
| 48 | $cron_filename = '/var/spool/cron/crontabs/root'; |
||
| 49 | $cron_user = ''; |
||
| 50 | } |
||
| 51 | |||
| 52 | $workerSafeScriptsPath = Util::getFilePathByClassName(WorkerSafeScriptsCore::class); |
||
| 53 | $phpPath = Util::which('php'); |
||
| 54 | $WorkerSafeScripts = "{$phpPath} -f {$workerSafeScriptsPath} start > /dev/null 2> /dev/null"; |
||
| 55 | |||
| 56 | $workersPath = appPath('src/Core/Workers'); |
||
| 57 | |||
| 58 | $restart_night = $this->mikoPBXConfig->getGeneralSettings('RestartEveryNight'); |
||
| 59 | $asteriskPath = Util::which('asterisk'); |
||
| 60 | $ntpdPath = Util::which('ntpd'); |
||
| 61 | $shPath = Util::which('sh'); |
||
| 62 | if ($restart_night === '1') { |
||
| 63 | $mast_have[] = '0 1 * * * ' . $cron_user . $asteriskPath . ' -rx"core restart now" > /dev/null 2> /dev/null' . "\n"; |
||
| 64 | } |
||
| 65 | $mast_have[] = '*/5 * * * * ' . $cron_user . $ntpdPath . ' -q > /dev/null 2> /dev/null' . "\n"; |
||
| 66 | $mast_have[] = '*/6 * * * * ' . $cron_user . "{$shPath} {$workersPath}/Cron/cleaner_download_links.sh > /dev/null 2> /dev/null\n"; |
||
| 67 | $mast_have[] = '*/1 * * * * ' . $cron_user . "{$WorkerSafeScripts}\n"; |
||
| 68 | |||
| 69 | $tasks = []; |
||
| 70 | |||
| 71 | // Add additional modules includes |
||
| 72 | foreach ($additionalModules as $appClass) { |
||
| 73 | /** @var \MikoPBX\Modules\Config\ConfigClass $appClass */ |
||
| 74 | $appClass->createCronTasks($tasks); |
||
| 75 | } |
||
| 76 | $conf = implode('', array_merge($mast_have, $tasks)); |
||
| 77 | |||
| 78 | if (Util::isSystemctl()) { |
||
| 79 | // Convert rules to debian style |
||
| 80 | $conf = str_replace(' * * * * /', ' * * * * root /', $conf); |
||
| 81 | } |
||
| 82 | |||
| 83 | if ($boot === true) { |
||
| 84 | Util::mwExecBg($WorkerSafeScripts); |
||
| 85 | } |
||
| 86 | |||
| 87 | Util::fileWriteContent($cron_filename, $conf); |
||
| 88 | } |
||
| 111 | } |