| Conditions | 15 |
| Paths | 242 |
| Total Lines | 70 |
| Code Lines | 47 |
| 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 |
||
| 77 | function get_gpu_list($vendor) { |
||
| 78 | |||
| 79 | // plan class names contain: |
||
| 80 | // nvidia |
||
| 81 | // amd or ati |
||
| 82 | // intel |
||
| 83 | // apple |
||
| 84 | |||
| 85 | $clause = "plan_class like '%$vendor%'"; |
||
| 86 | if ($vendor == 'amd') { |
||
| 87 | $clause .= " or plan_class like '%ati%'"; |
||
| 88 | } |
||
| 89 | $avs = BoincAppVersion::enum($clause); |
||
| 90 | if (count($avs) == 0) { |
||
| 91 | $x = new StdClass; |
||
| 92 | $x->total = array(); |
||
| 93 | return $x; |
||
| 94 | } |
||
| 95 | |||
| 96 | $av_ids = []; |
||
| 97 | foreach($avs as $av) { |
||
| 98 | $av_ids[] = $av->id; |
||
| 99 | } |
||
| 100 | if ($vendor == "nvidia") { |
||
| 101 | $av_ids[] = ANON_PLATFORM_NVIDIA; |
||
| 102 | } else if ($vendor == "amd") { |
||
| 103 | $av_ids[] = ANON_PLATFORM_ATI; |
||
| 104 | } else if ($vendor == "intel") { |
||
| 105 | $av_ids[] = ANON_PLATFORM_INTEL_GPU; |
||
| 106 | } else if ($vendor == "apple") { |
||
| 107 | $av_ids[] = ANON_PLATFORM_APPLE_GPU; |
||
| 108 | } |
||
| 109 | |||
| 110 | $av_ids = implode(',', $av_ids); |
||
| 111 | |||
| 112 | $t = time() - 30*86400; |
||
| 113 | //echo "start enum $vendor $av_ids\n"; |
||
| 114 | $results = BoincResult::enum( |
||
| 115 | "app_version_id in ($av_ids) and create_time > $t and elapsed_time>100 limit 2000" |
||
| 116 | ); |
||
| 117 | //echo "end enum\n"; |
||
| 118 | $total = array(); |
||
| 119 | $win = array(); |
||
| 120 | $linux = array(); |
||
| 121 | $mac = array(); |
||
| 122 | foreach ($results as $r) { |
||
| 123 | $h = BoincHost::lookup_id($r->hostid); |
||
| 124 | if (!$h) continue; |
||
| 125 | $wu = BoincWorkunit::lookup_id($r->workunitid); |
||
| 126 | if (!$wu) continue; |
||
| 127 | $model = get_gpu_model(json_decode($h->misc), $vendor); |
||
| 128 | if (!$model) continue; |
||
| 129 | add_model($model, $r, $wu, $total); |
||
| 130 | if (strstr($h->os_name, "Windows")) { |
||
| 131 | add_model($model, $r, $wu, $win); |
||
| 132 | } |
||
| 133 | if (strstr($h->os_name, "Linux")) { |
||
| 134 | add_model($model, $r, $wu, $linux); |
||
| 135 | } |
||
| 136 | if (strstr($h->os_name, "Darwin")) { |
||
| 137 | add_model($model, $r, $wu, $mac); |
||
| 138 | } |
||
| 139 | |||
| 140 | } |
||
| 141 | $x = new StdClass; |
||
| 142 | $x->total = $total; |
||
| 143 | $x->win = $win; |
||
| 144 | $x->linux = $linux; |
||
| 145 | $x->mac = $mac; |
||
| 146 | return $x; |
||
| 147 | } |
||
| 235 |