Conditions | 12 |
Paths | 64 |
Total Lines | 35 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
46 | public function handle() |
||
47 | { |
||
48 | $logs = []; |
||
49 | |||
50 | $cpuUsage = $this->cpu->check(); |
||
51 | $memoryUsage = $this->memory->check(); |
||
52 | $networkStatus = $this->network->check(); |
||
53 | $storageFreeSpace = $this->storage->check(); |
||
54 | $webServerStatuses = $this->webServer->check(); |
||
55 | |||
56 | if (config('stethoscope.monitorable_resources.cpu') && $cpuUsage > config(('stethoscope.thresholds.cpu'))) { |
||
57 | $logs['cpu'] = $cpuUsage; |
||
58 | } |
||
59 | |||
60 | if ($memoryUsage > config(('stethoscope.thresholds.memory')) && config('stethoscope.monitorable_resources.memory')) { |
||
61 | $logs['memory'] = $memoryUsage; |
||
62 | } |
||
63 | |||
64 | if ($networkStatus == 'disconnected' && config('stethoscope.monitorable_resources.network')) { |
||
65 | $logs['network'] = $networkStatus; |
||
66 | } |
||
67 | |||
68 | if ($storageFreeSpace < config(('stethoscope.thresholds.storage')) && config('stethoscope.monitorable_resources.storage')) { |
||
69 | $logs['storage'] = $storageFreeSpace; |
||
70 | } |
||
71 | |||
72 | if ($webServerStatuses != 'active' && config('stethoscope.monitorable_resources.web_server')) { |
||
73 | $logs['webServer'] = $webServerStatuses; |
||
74 | } |
||
75 | |||
76 | Record::record($logs); |
||
77 | |||
78 | if (! empty($logs)) { |
||
79 | $logs['signature'] = $this->signature; |
||
80 | TroubleOccurred::dispatch($logs); |
||
81 | } |
||
84 |