| 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 |
||
| 3 | public function buildcloudlayer($metar) { |
||
| 4 | //print_r($metar); |
||
| 5 | $result = array(); |
||
| 6 | foreach($metar['cloud'] as $key => $data) { |
||
| 7 | $alt_m = $metar['cloud'][$key]['level']; |
||
| 8 | $alt_ft = $alt_m*3.28084; |
||
| 9 | $pressure = $metar['QNH']; |
||
| 10 | $cumulus_base = 122.0 * ($metar['temperature'] - $metar['dew']); |
||
| 11 | $stratus_base = 100.0 * (100.0 * $metar['rh'])*0.3048; |
||
| 12 | $coverage_norm = 0.0; |
||
| 13 | if ($metar['cloud'][$key]['type'] == 'Few') { |
||
| 14 | $coverage_norm = 2.0/8.0; |
||
| 15 | } elseif ($metar['cloud'][$key]['type'] == 'Scattered') { |
||
| 16 | $coverage_norm = 4.0/8.0; |
||
| 17 | } elseif ($metar['cloud'][$key]['type'] == 'Broken') { |
||
| 18 | $coverage_norm = 6.0/8.0; |
||
| 19 | } elseif ($metar['cloud'][$key]['type'] == 'Overcast/Full cloud coverage') { |
||
| 20 | $coverage_norm = 8.0/8.0; |
||
| 21 | } |
||
| 22 | $layer_type = 'nn'; |
||
|
|
|||
| 23 | if ($metar['cloud'][$key]['significant'] == 'cirrus') { |
||
| 24 | $layer_type = 'ci'; |
||
| 25 | } elseif ($alt_ft > 16500) { |
||
| 26 | $layer_type = 'ci'; |
||
| 27 | } elseif ($alt_ft > 6500) { |
||
| 28 | $layer_type = 'ac'; |
||
| 29 | if ($pressure < 1005.0 && $coverage_norm >= 0.5) { |
||
| 30 | $layer_type = 'ns'; |
||
| 31 | } |
||
| 32 | } else { |
||
| 33 | if ($cumulus_base * 0.80 < $alt_m && $cumulus_base * 1.20 > $alt_m) { |
||
| 34 | $layer_type = 'cu'; |
||
| 35 | } elseif ($stratus_base * 0.80 < $alt_m && $stratus_base * 1.40 > $alt_m) { |
||
| 36 | $layer_type = 'st'; |
||
| 37 | } else { |
||
| 38 | if ($alt_ft < 2000) { |
||
| 39 | $layer_type = 'st'; |
||
| 40 | } elseif ($alt_ft < 4500) { |
||
| 41 | $layer_type = 'cu'; |
||
| 42 | } else { |
||
| 43 | $layer_type = 'sc'; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | //echo 'coverage norm : '.$coverage_norm.' - layer_type: '.$layer_type."\n"; |
||
| 48 | $result[] = array('cov' => $coverage_norm, 'type' => $layer_type,'alt' => $alt_m,'rh' => $metar['rh']); |
||
| 49 | } |
||
| 50 | if (count($result) < 2 && $metar['rh'] > 60) { |
||
| 51 | $result[] = array('cov' => 0.75, 'type' => 'cu','alt' => 4000,'rh' => $metar['rh']); |
||
| 52 | } |
||
| 53 | return $result; |
||
| 54 | } |
||
| 55 | } |
||
| 73 | ?> |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.