| Conditions | 19 |
| Paths | 512 |
| Total Lines | 77 |
| Code Lines | 45 |
| 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 |
||
| 187 | protected function createOptionalWindows(): void |
||
| 188 | { |
||
| 189 | $windowIndex = 4; |
||
| 190 | |||
| 191 | // htop |
||
| 192 | if ((int) Settings::settingValue('htop') === 1 && $this->commandExists('htop')) { |
||
| 193 | $this->paneManager->createWindow($windowIndex, 'htop'); |
||
| 194 | $this->paneManager->respawnPane("{$windowIndex}.0", 'htop'); |
||
| 195 | $windowIndex++; |
||
| 196 | } |
||
| 197 | |||
| 198 | // nmon |
||
| 199 | if ((int) Settings::settingValue('nmon') === 1 && $this->commandExists('nmon')) { |
||
| 200 | $this->paneManager->createWindow($windowIndex, 'nmon'); |
||
| 201 | $this->paneManager->respawnPane("{$windowIndex}.0", 'nmon -t'); |
||
| 202 | $windowIndex++; |
||
| 203 | } |
||
| 204 | |||
| 205 | // vnstat |
||
| 206 | if ((int) Settings::settingValue('vnstat') === 1 && $this->commandExists('vnstat')) { |
||
| 207 | $vnstatArgs = Settings::settingValue('vnstat_args') ?? ''; |
||
| 208 | $this->paneManager->createWindow($windowIndex, 'vnstat'); |
||
| 209 | $this->paneManager->respawnPane("{$windowIndex}.0", "watch -n10 'vnstat {$vnstatArgs}'"); |
||
| 210 | $windowIndex++; |
||
| 211 | } |
||
| 212 | |||
| 213 | // tcptrack |
||
| 214 | if ((int) Settings::settingValue('tcptrack') === 1 && $this->commandExists('tcptrack')) { |
||
| 215 | $tcptrackArgs = Settings::settingValue('tcptrack_args') ?? ''; |
||
| 216 | $this->paneManager->createWindow($windowIndex, 'tcptrack'); |
||
| 217 | $this->paneManager->respawnPane("{$windowIndex}.0", "tcptrack {$tcptrackArgs}"); |
||
| 218 | $windowIndex++; |
||
| 219 | } |
||
| 220 | |||
| 221 | // bwm-ng |
||
| 222 | if ((int) Settings::settingValue('bwmng') === 1 && $this->commandExists('bwm-ng')) { |
||
| 223 | $this->paneManager->createWindow($windowIndex, 'bwm-ng'); |
||
| 224 | $this->paneManager->respawnPane("{$windowIndex}.0", 'bwm-ng'); |
||
| 225 | $windowIndex++; |
||
| 226 | } |
||
| 227 | |||
| 228 | // mytop |
||
| 229 | if ((int) Settings::settingValue('mytop') === 1 && $this->commandExists('mytop')) { |
||
| 230 | $this->paneManager->createWindow($windowIndex, 'mytop'); |
||
| 231 | $this->paneManager->respawnPane("{$windowIndex}.0", 'mytop -u'); |
||
| 232 | $windowIndex++; |
||
| 233 | } |
||
| 234 | |||
| 235 | // redis monitoring |
||
| 236 | if ((int) Settings::settingValue('redis') === 1 && $this->commandExists('redis-cli')) { |
||
| 237 | $redisHost = config('database.redis.default.host', '127.0.0.1'); |
||
| 238 | $redisPort = config('database.redis.default.port', 6379); |
||
| 239 | $redisArgs = Settings::settingValue('redis_args') ?? ''; |
||
| 240 | $refreshInterval = 2; |
||
| 241 | |||
| 242 | $this->paneManager->createWindow($windowIndex, 'redis'); |
||
| 243 | |||
| 244 | // Check if custom args provided for simple redis-cli output |
||
| 245 | if (! empty($redisArgs) && $redisArgs !== 'NULL') { |
||
| 246 | $this->paneManager->respawnPane("{$windowIndex}.0", "watch -n{$refreshInterval} -c 'redis-cli -h {$redisHost} -p {$redisPort} {$redisArgs}'"); |
||
| 247 | } else { |
||
| 248 | // Use modern visual monitoring script |
||
| 249 | $monitorScript = base_path('misc/redis-monitor.sh'); |
||
| 250 | if (file_exists($monitorScript)) { |
||
| 251 | $this->paneManager->respawnPane("{$windowIndex}.0", "bash {$monitorScript} {$redisHost} {$redisPort} {$refreshInterval}"); |
||
| 252 | } else { |
||
| 253 | // Fallback to basic redis-cli info with color |
||
| 254 | $this->paneManager->respawnPane("{$windowIndex}.0", "watch -n{$refreshInterval} -c 'redis-cli -h {$redisHost} -p {$redisPort} info'"); |
||
| 255 | } |
||
| 256 | } |
||
| 257 | $windowIndex++; |
||
| 258 | } |
||
| 259 | |||
| 260 | // bash console |
||
| 261 | if ((int) Settings::settingValue('console') === 1) { |
||
| 262 | $this->paneManager->createWindow($windowIndex, 'bash'); |
||
| 263 | $this->paneManager->respawnPane("{$windowIndex}.0", 'bash -i'); |
||
| 264 | } |
||
| 278 |