Conditions | 10 |
Paths | 32 |
Total Lines | 94 |
Code Lines | 76 |
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 |
||
49 | public function renderStats(): Template |
||
50 | { |
||
51 | $statsraw = Memcache::getStats(); |
||
52 | $stats = $statsraw; |
||
53 | |||
54 | foreach ($stats as $key => &$entry) { |
||
55 | if (array_key_exists($key, $this->formats)) { |
||
56 | $func = $this->formats[$key]; |
||
57 | foreach ($entry as $k => $val) { |
||
58 | $entry[$k] = call_user_func($func, $val); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | $t = new Template($this->config, 'memcacheMonitor:memcachestat.twig'); |
||
64 | $rowTitles = [ |
||
65 | 'accepting_conns' => Translate::noop('{memcacheMonitor:memcachestat:accepting_conns}'), |
||
66 | 'auth_cmds' => Translate::noop('{memcacheMonitor:memcachestat:auth_cmds}'), |
||
67 | 'auth_errors' => Translate::noop('{memcacheMonitor:memcachestat:auth_errors}'), |
||
68 | 'bytes' => Translate::noop('{memcacheMonitor:memcachestat:bytes}'), |
||
69 | 'bytes_read' => Translate::noop('{memcacheMonitor:memcachestat:bytes_read}'), |
||
70 | 'bytes_written' => Translate::noop('{memcacheMonitor:memcachestat:bytes_written}'), |
||
71 | 'cas_badval' => Translate::noop('{memcacheMonitor:memcachestat:cas_badval}'), |
||
72 | 'cas_hits' => Translate::noop('{memcacheMonitor:memcachestat:cas_hits}'), |
||
73 | 'cas_misses' => Translate::noop('{memcacheMonitor:memcachestat:cas_misses}'), |
||
74 | 'cmd_flush' => Translate::noop('{memcacheMonitor:memcachestat:cmd_flush}'), |
||
75 | 'cmd_get' => Translate::noop('{memcacheMonitor:memcachestat:cmd_get}'), |
||
76 | 'cmd_set' => Translate::noop('{memcacheMonitor:memcachestat:cmd_set}'), |
||
77 | 'cmd_touch' => Translate::noop('{memcacheMonitor:memcachestat:cmd_touch}'), |
||
78 | 'connection_structures' => Translate::noop('{memcacheMonitor:memcachestat:connection_structures}'), |
||
79 | 'conn_yields' => Translate::noop('{memcacheMonitor:memcachestat:conn_yields}'), |
||
80 | 'curr_connections' => Translate::noop('{memcacheMonitor:memcachestat:curr_connections}'), |
||
81 | 'curr_items' => Translate::noop('{memcacheMonitor:memcachestat:curr_items}'), |
||
82 | 'decr_hits' => Translate::noop('{memcacheMonitor:memcachestat:decr_hits}'), |
||
83 | 'decr_misses' => Translate::noop('{memcacheMonitor:memcachestat:decr_misses}'), |
||
84 | 'delete_hits' => Translate::noop('{memcacheMonitor:memcachestat:delete_hits}'), |
||
85 | 'delete_misses' => Translate::noop('{memcacheMonitor:memcachestat:delete_misses}'), |
||
86 | 'expired_unfetched' => Translate::noop('{memcacheMonitor:memcachestat:expired_unfetched}'), |
||
87 | 'evicted_unfetched' => Translate::noop('{memcacheMonitor:memcachestat:evicted_unfetched}'), |
||
88 | 'evictions' => Translate::noop('{memcacheMonitor:memcachestat:evictions}'), |
||
89 | 'get_hits' => Translate::noop('{memcacheMonitor:memcachestat:get_hits}'), |
||
90 | 'get_misses' => Translate::noop('{memcacheMonitor:memcachestat:get_misses}'), |
||
91 | 'hash_bytes' => Translate::noop('{memcacheMonitor:memcachestat:hash_bytes}'), |
||
92 | 'hash_is_expanding' => Translate::noop('{memcacheMonitor:memcachestat:hash_is_expanding}'), |
||
93 | 'hash_power_level' => Translate::noop('{memcacheMonitor:memcachestat:hash_power_level}'), |
||
94 | 'incr_hits' => Translate::noop('{memcacheMonitor:memcachestat:incr_hits}'), |
||
95 | 'incr_misses' => Translate::noop('{memcacheMonitor:memcachestat:incr_misses}'), |
||
96 | 'libevent' => Translate::noop('{memcacheMonitor:memcachestat:libevent}'), |
||
97 | 'limit_maxbytes' => Translate::noop('{memcacheMonitor:memcachestat:limit_maxbytes}'), |
||
98 | 'listen_disabled_num' => Translate::noop('{memcacheMonitor:memcachestat:listen_disabled_num}'), |
||
99 | 'pid' => Translate::noop('{memcacheMonitor:memcachestat:pid}'), |
||
100 | 'pointer_size' => Translate::noop('{memcacheMonitor:memcachestat:pointer_size}'), |
||
101 | 'reclaimed' => Translate::noop('{memcacheMonitor:memcachestat:reclaimed}'), |
||
102 | 'reserved_fds' => Translate::noop('{memcacheMonitor:memcachestat:reserved_fds}'), |
||
103 | 'rusage_system' => Translate::noop('{memcacheMonitor:memcachestat:rusage_system}'), |
||
104 | 'rusage_user' => Translate::noop('{memcacheMonitor:memcachestat:rusage_user}'), |
||
105 | 'threads' => Translate::noop('{memcacheMonitor:memcachestat:threads}'), |
||
106 | 'time' => Translate::noop('{memcacheMonitor:memcachestat:time}'), |
||
107 | 'total_connections' => Translate::noop('{memcacheMonitor:memcachestat:total_connections}'), |
||
108 | 'total_items' => Translate::noop('{memcacheMonitor:memcachestat:total_items}'), |
||
109 | 'touch_hits' => Translate::noop('{memcacheMonitor:memcachestat:touch_hits}'), |
||
110 | 'touch_misses' => Translate::noop('{memcacheMonitor:memcachestat:touch_misses}'), |
||
111 | 'uptime' => Translate::noop('{memcacheMonitor:memcachestat:uptime}'), |
||
112 | 'version' => Translate::noop('{memcacheMonitor:memcachestat:version}'), |
||
113 | ]; |
||
114 | |||
115 | // Identify column headings |
||
116 | $colTitles = []; |
||
117 | foreach ($stats as $rowTitle => $rowData) { |
||
118 | foreach ($rowData as $colTitle => $foo) { |
||
119 | if (!in_array($colTitle, $colTitles, true)) { |
||
120 | $colTitles[] = $colTitle; |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | if (array_key_exists('bytes', $statsraw) && array_key_exists('limit_maxbytes', $statsraw)) { |
||
126 | $usage = []; |
||
127 | $maxpix = 400; |
||
128 | foreach ($statsraw['bytes'] as $key => $row_data) { |
||
129 | $pix = floor($statsraw['bytes'][$key] * $maxpix / $statsraw['limit_maxbytes'][$key]); |
||
130 | $usage[$key] = $pix . 'px'; |
||
131 | } |
||
132 | $t->data['maxpix'] = $maxpix . 'px'; |
||
133 | $t->data['usage'] = $usage; |
||
134 | } |
||
135 | |||
136 | $t->data['title'] = 'Memcache stats'; |
||
137 | $t->data['rowTitles'] = $rowTitles; |
||
138 | $t->data['colTitles'] = $colTitles; |
||
139 | $t->data['statsraw'] = $statsraw; |
||
140 | $t->data['table'] = $stats; |
||
141 | |||
142 | return $t; |
||
143 | } |
||
230 |