| Conditions | 15 |
| Paths | 192 |
| Total Lines | 35 |
| 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 |
||
| 13 | public function record($cpuUsage, $memoryUsage, $networkStatus, $webServerStatuses, $hardDiskFreeSpace) |
||
| 14 | { |
||
| 15 | $file = config('stethoscope.log_file_storage.path') . now()->format('Y-m-d'); |
||
| 16 | |||
| 17 | $this->storage = Storage::disk(config('stethoscope.log_file_storage.driver')); |
||
|
|
|||
| 18 | |||
| 19 | $log = ''; |
||
| 20 | |||
| 21 | if ($cpuUsage > config(('stethoscope.thresholds.cpu')) && config('stethoscope.monitorable_resources.cpu')) |
||
| 22 | $log .= $this->cpuMessage($cpuUsage) . "\n"; |
||
| 23 | |||
| 24 | if ($memoryUsage > config(('stethoscope.thresholds.memory')) && config('stethoscope.monitorable_resources.memory')) |
||
| 25 | $log .= $this->memoryMessage($memoryUsage) . "\n"; |
||
| 26 | |||
| 27 | if (!$networkStatus && config('stethoscope.monitorable_resources.network')) |
||
| 28 | $log .= $this->networkMessage($networkStatus) . "\n"; |
||
| 29 | |||
| 30 | if (($webServerStatuses['nginx'] != 'active' && config('stethoscope.monitorable_resources.web_server'))) { |
||
| 31 | $log .= $this->webServerMessage('nginx', $webServerStatuses['nginx']) . "\n"; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (($webServerStatuses['apache'] != 'active' && config('stethoscope.monitorable_resources.web_server'))) { |
||
| 35 | $log .= $this->webServerMessage('apache', $webServerStatuses['apache']) . "\n"; |
||
| 36 | } |
||
| 37 | |||
| 38 | if ($hardDiskFreeSpace < config(('stethoscope.thresholds.hard_disk')) && config('stethoscope.monitorable_resources.hard_disk')) |
||
| 39 | $log .= $this->hardDiskMessage($hardDiskFreeSpace) . "\n"; |
||
| 40 | |||
| 41 | if ($log != '') { |
||
| 42 | $log = $this->timeMessage() . "\n" . $log; |
||
| 43 | |||
| 44 | if ($this->storage->exists($file)) |
||
| 45 | $log = $this->storage->get($file) . "\n \n" . $log; |
||
| 46 | |||
| 47 | $this->storage->put($file, $log); |
||
| 48 | } |
||
| 51 |