| Conditions | 19 |
| Paths | 92 |
| Total Lines | 52 |
| Code Lines | 42 |
| 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 |
||
| 38 | function buildcloudlayer($metar) { |
||
| 39 | //print_r($metar); |
||
| 40 | $result = array(); |
||
| 41 | foreach($metar['cloud'] as $key => $data) { |
||
| 42 | $alt_m = $metar['cloud'][$key]['level']; |
||
| 43 | $alt_ft = $alt_m*3.28084; |
||
| 44 | $pressure = $metar['QNH']; |
||
| 45 | $cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']); |
||
| 46 | $stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048; |
||
| 47 | $coverage_norm = 0.0; |
||
| 48 | if ($metar['cloud'][$key]['type'] == 'Few') { |
||
| 49 | $coverage_norm = 2.0/8.0; |
||
| 50 | } elseif ($metar['cloud'][$key]['type'] == 'Scattered') { |
||
| 51 | $coverage_norm = 4.0/8.0; |
||
| 52 | } elseif ($metar['cloud'][$key]['type'] == 'Broken') { |
||
| 53 | $coverage_norm = 6.0/8.0; |
||
| 54 | } elseif ($metar['cloud'][$key]['type'] == 'Overcast/Full cloud coverage') { |
||
| 55 | $coverage_norm = 8.0/8.0; |
||
| 56 | } |
||
| 57 | $layer_type = 'nn'; |
||
| 58 | if ($metar['cloud'][$key]['significant'] == 'cirrus') { |
||
| 59 | $layer_type = 'ci'; |
||
| 60 | } elseif ($alt_ft > 16500) { |
||
| 61 | $layer_type = 'ci'; |
||
| 62 | } elseif ($alt_ft > 6500) { |
||
| 63 | $layer_type = 'ac'; |
||
| 64 | if ($pressure < 1005.0 && $coverage_norm >= 0.5) { |
||
| 65 | $layer_type = 'ns'; |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
||
| 69 | $layer_type = 'cu'; |
||
| 70 | } elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
||
| 71 | $layer_type = 'st'; |
||
| 72 | } else { |
||
| 73 | if ($alt_ft < 2000) { |
||
| 74 | $layer_type = 'st'; |
||
| 75 | } elseif ($alt_ft < 4500) { |
||
| 76 | $layer_type = 'cu'; |
||
| 77 | } else { |
||
| 78 | $layer_type = 'sc'; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | //echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n"; |
||
| 83 | $result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']); |
||
| 84 | } |
||
| 85 | if (count($result) < 2 && $metar['rh'] > 60) { |
||
| 86 | $result[] = array('cov' => 0.75, 'type' => 'cu','alt' => 4000,'rh' => $metar['rh']); |
||
| 87 | } |
||
| 88 | return $result; |
||
| 89 | } |
||
| 90 | |||
| 124 | ?> |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.