Completed
Push — development ( 0e2272...f5cb54 )
by Thomas
59:34 queued 50:32
created

function.coordinput.php ➔ smarty_function_coordinput()   D

Complexity

Conditions 9
Paths 64

Size

Total Lines 102
Code Lines 84

Duplication

Lines 6
Ratio 5.88 %

Importance

Changes 0
Metric Value
cc 9
eloc 84
nc 64
nop 2
dl 6
loc 102
rs 4.8196
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * Smarty plugin
4
 *
5
 * @package Smarty
6
 * @subpackage plugins
7
 * Smarty {coordinput prefix="coord" lat=48.12345 lon=9.12345} function plugin
8
 */
9
function smarty_function_coordinput($params, &$smarty)
0 ignored issues
show
Unused Code introduced by
The parameter $smarty is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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>&nbsp;';
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" />&deg; ';
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) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $params['laterror'] of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
67
        $returnValue .= ' &nbsp; <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>&nbsp;';
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" />&deg; ';
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) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $params['lonerror'] of type integer to the boolean true. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
106
        $returnValue .= ' &nbsp; <span class="errormsg">' . gettext('Invalid coordinate') . '</span>';
107
    }
108
109
    return $returnValue;
110
}
111