| Conditions | 9 |
| Paths | 64 |
| Total Lines | 102 |
| Code Lines | 84 |
| Lines | 6 |
| Ratio | 5.88 % |
| 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 |
||
| 9 | function smarty_function_coordinput($params, &$smarty) |
||
|
|
|||
| 10 | { |
||
| 11 | $prefix = $params['prefix']; |
||
| 12 | $lat = $params['lat'] + 0; |
||
| 13 | $lon = $params['lon'] + 0; |
||
| 14 | |||
| 15 | if ($lat < 0) { |
||
| 16 | $bLatNeg = true; |
||
| 17 | $lat = -$lat; |
||
| 18 | } else { |
||
| 19 | $bLatNeg = false; |
||
| 20 | } |
||
| 21 | $latMin = $lat - floor($lat); |
||
| 22 | $lat -= $latMin; |
||
| 23 | |||
| 24 | if ($lon < 0) { |
||
| 25 | $bLonNeg = true; |
||
| 26 | $lon = -$lon; |
||
| 27 | } else { |
||
| 28 | $bLonNeg = false; |
||
| 29 | } |
||
| 30 | $lonMin = $lon - floor($lon); |
||
| 31 | $lon -= $lonMin; |
||
| 32 | |||
| 33 | $returnValue = '<select name="' . htmlspecialchars($prefix, ENT_QUOTES, 'UTF-8') . 'NS">'; |
||
| 34 | if ($bLatNeg) { |
||
| 35 | $returnValue .= '<option value="N">N</option>'; |
||
| 36 | $returnValue .= '<option value="S" selected="selected">S</option>'; |
||
| 37 | } else { |
||
| 38 | $returnValue .= '<option value="N" selected="selected">N</option>'; |
||
| 39 | $returnValue .= '<option value="S">S</option>'; |
||
| 40 | } |
||
| 41 | $returnValue .= '</select> '; |
||
| 42 | |||
| 43 | $returnValue .= '<input type="text" name="' . |
||
| 44 | htmlspecialchars( |
||
| 45 | $prefix, |
||
| 46 | ENT_QUOTES, |
||
| 47 | 'UTF-8' |
||
| 48 | ) . 'Lat" value="' . |
||
| 49 | htmlspecialchars( |
||
| 50 | sprintf('%02d', $lat), |
||
| 51 | ENT_QUOTES, |
||
| 52 | 'UTF-8' |
||
| 53 | ) . '" size="1" maxlength="2" />° '; |
||
| 54 | $returnValue .= '<input type="text" name="' . |
||
| 55 | htmlspecialchars( |
||
| 56 | $prefix, |
||
| 57 | ENT_QUOTES, |
||
| 58 | 'UTF-8' |
||
| 59 | ) . 'LatMin" value="' . |
||
| 60 | htmlspecialchars( |
||
| 61 | sprintf('%06.3f', $latMin * 60), |
||
| 62 | ENT_QUOTES, |
||
| 63 | 'UTF-8' |
||
| 64 | ) . '" size="5" maxlength="6" /> \''; |
||
| 65 | |||
| 66 | View Code Duplication | if (isset($params['laterror']) && $params['laterror'] == true) { |
|
| 67 | $returnValue .= ' <span class="errormsg">' . gettext('Invalid coordinate') . '</span>'; |
||
| 68 | } |
||
| 69 | |||
| 70 | $returnValue .= '<br />'; |
||
| 71 | |||
| 72 | $returnValue .= '<select name="' . htmlspecialchars($prefix, ENT_QUOTES, 'UTF-8') . 'EW">'; |
||
| 73 | if ($bLonNeg) { |
||
| 74 | $returnValue .= '<option value="E">E</option>'; |
||
| 75 | $returnValue .= '<option value="W" selected="selected">W</option>'; |
||
| 76 | } else { |
||
| 77 | $returnValue .= '<option value="E" selected="selected">E</option>'; |
||
| 78 | $returnValue .= '<option value="W">W</option>'; |
||
| 79 | } |
||
| 80 | $returnValue .= '</select> '; |
||
| 81 | |||
| 82 | $returnValue .= '<input type="text" name="' . |
||
| 83 | htmlspecialchars( |
||
| 84 | $prefix, |
||
| 85 | ENT_QUOTES, |
||
| 86 | 'UTF-8' |
||
| 87 | ) . 'Lon" value="' . |
||
| 88 | htmlspecialchars( |
||
| 89 | sprintf('%03d', $lon), |
||
| 90 | ENT_QUOTES, |
||
| 91 | 'UTF-8' |
||
| 92 | ) . '" size="2" maxlength="3" />° '; |
||
| 93 | $returnValue .= '<input type="text" name="' . |
||
| 94 | htmlspecialchars( |
||
| 95 | $prefix, |
||
| 96 | ENT_QUOTES, |
||
| 97 | 'UTF-8' |
||
| 98 | ) . 'LonMin" value="' . |
||
| 99 | htmlspecialchars( |
||
| 100 | sprintf('%06.3f', $lonMin * 60), |
||
| 101 | ENT_QUOTES, |
||
| 102 | 'UTF-8' |
||
| 103 | ) . '" size="5" maxlength="6" /> \''; |
||
| 104 | |||
| 105 | View Code Duplication | if (isset($params['lonerror']) && $params['lonerror'] == true) { |
|
| 106 | $returnValue .= ' <span class="errormsg">' . gettext('Invalid coordinate') . '</span>'; |
||
| 107 | } |
||
| 108 | |||
| 109 | return $returnValue; |
||
| 110 | } |
||
| 111 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.