| Conditions | 15 |
| Paths | 145 |
| Total Lines | 49 |
| Code Lines | 39 |
| 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 |
||
| 52 | function show_graph() { |
||
| 53 | db_init(); |
||
| 54 | |||
| 55 | $xaxis = $_GET['xaxis']; |
||
| 56 | $yaxis = $_GET['yaxis']; |
||
| 57 | $granularity = $_GET['granularity']; |
||
| 58 | $active = $_GET['active']; |
||
| 59 | $inactive = $_GET['inactive']; |
||
| 60 | $show_text = $_GET['show_text']; |
||
| 61 | |||
| 62 | if (!$active && !$inactive) { |
||
| 63 | echo "You must select at least one of (active, inactive)"; |
||
| 64 | exit(); |
||
| 65 | } |
||
| 66 | |||
| 67 | $fields = 'host.id, user.create_time'; |
||
| 68 | if ($xaxis == 'active' || !$active || !$inactive) { |
||
| 69 | $query = "select $fields, max(rpc_time) as max_rpc_time from host, user where host.userid=user.id group by userid"; |
||
| 70 | } else { |
||
| 71 | $query = 'select $fields from user'; |
||
| 72 | } |
||
| 73 | $result = _mysql_query($query); |
||
| 74 | $yarr = array(); |
||
| 75 | $now = time(); |
||
| 76 | $maxind = 0; |
||
| 77 | $active_thresh = time() - 30*86400; |
||
| 78 | while ($user = _mysql_fetch_object($result)) { |
||
| 79 | $val = $now - $user->max_rpc_time; |
||
| 80 | if (!$active) { |
||
| 81 | if ($user->max_rpc_time > $active_thresh) continue; |
||
| 82 | } |
||
| 83 | if (!$inactive) { |
||
| 84 | if ($user->max_rpc_time < $active_thresh) continue; |
||
| 85 | } |
||
| 86 | $life = $user->max_rpc_time - $user->create_time; |
||
| 87 | $ind = $life/$granularity; |
||
| 88 | $ind = (int)$ind; |
||
| 89 | $yarr[$ind]++; |
||
| 90 | if ($ind > $maxind) $maxind = $ind; |
||
| 91 | } |
||
| 92 | $xarr = array(); |
||
| 93 | for ($i=0; $i<=$maxind; $i++) { |
||
| 94 | $xarr[$i] = $i; |
||
| 95 | if (is_null($yarr[$i])) $yarr[$i]=0; |
||
| 96 | } |
||
| 97 | if ($show_text) { |
||
| 98 | show_text($xarr, $yarr); |
||
| 99 | } else { |
||
| 100 | draw_graph($xarr, $yarr); |
||
| 101 | } |
||
| 149 |