| Conditions | 7 |
| Paths | 48 |
| Total Lines | 73 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 3 |
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 |
||
| 41 | public function getSwooleMetrics() |
||
| 42 | { |
||
| 43 | /**@var \Swoole\Http\Server $swoole */ |
||
| 44 | $swoole = app('swoole'); |
||
| 45 | $stats = $swoole->stats(); |
||
| 46 | // Get worker_num/task_worker_num from setting for the old Swoole. |
||
| 47 | $setting = $swoole->setting; |
||
| 48 | if (!isset($stats['worker_num'])) { |
||
| 49 | $stats['worker_num'] = $setting['worker_num']; |
||
| 50 | } |
||
| 51 | if (!isset($stats['task_worker_num'])) { |
||
| 52 | $stats['task_worker_num'] = isset($setting['task_worker_num']) ? $setting['task_worker_num'] : 0; |
||
| 53 | } |
||
| 54 | return [ |
||
| 55 | [ |
||
| 56 | 'name' => 'swoole_cpu_num', |
||
| 57 | 'help' => '', |
||
| 58 | 'type' => 'gauge', |
||
| 59 | 'value' => swoole_cpu_num(), |
||
| 60 | ], |
||
| 61 | [ |
||
| 62 | 'name' => 'swoole_start_time', |
||
| 63 | 'help' => '', |
||
| 64 | 'type' => 'gauge', |
||
| 65 | 'value' => $stats['start_time'], |
||
| 66 | ], |
||
| 67 | [ |
||
| 68 | 'name' => 'swoole_connection_num', |
||
| 69 | 'help' => '', |
||
| 70 | 'type' => 'gauge', |
||
| 71 | 'value' => $stats['connection_num'], |
||
| 72 | ], |
||
| 73 | [ |
||
| 74 | 'name' => 'swoole_request_count', |
||
| 75 | 'help' => '', |
||
| 76 | 'type' => 'gauge', |
||
| 77 | 'value' => $stats['request_count'], |
||
| 78 | ], |
||
| 79 | [ |
||
| 80 | 'name' => 'swoole_worker_num', |
||
| 81 | 'help' => '', |
||
| 82 | 'type' => 'gauge', |
||
| 83 | 'value' => $stats['worker_num'], |
||
| 84 | ], |
||
| 85 | [ |
||
| 86 | 'name' => 'swoole_idle_worker_num', |
||
| 87 | 'help' => '', |
||
| 88 | 'type' => 'gauge', |
||
| 89 | 'value' => isset($stats['idle_worker_num']) ? $stats['idle_worker_num'] : 0, |
||
| 90 | ], |
||
| 91 | [ |
||
| 92 | 'name' => 'swoole_task_worker_num', |
||
| 93 | 'help' => '', |
||
| 94 | 'type' => 'gauge', |
||
| 95 | 'value' => $stats['task_worker_num'], |
||
| 96 | ], |
||
| 97 | [ |
||
| 98 | 'name' => 'swoole_task_idle_worker_num', |
||
| 99 | 'help' => '', |
||
| 100 | 'type' => 'gauge', |
||
| 101 | 'value' => isset($stats['task_idle_worker_num']) ? $stats['task_idle_worker_num'] : 0, |
||
| 102 | ], |
||
| 103 | [ |
||
| 104 | 'name' => 'swoole_tasking_num', |
||
| 105 | 'help' => '', |
||
| 106 | 'type' => 'gauge', |
||
| 107 | 'value' => $stats['tasking_num'], |
||
| 108 | ], |
||
| 109 | [ |
||
| 110 | 'name' => 'swoole_coroutine_num', |
||
| 111 | 'help' => '', |
||
| 112 | 'type' => 'gauge', |
||
| 113 | 'value' => isset($stats['coroutine_num']) ? $stats['coroutine_num'] : 0, |
||
| 114 | ], |
||
| 177 | } |