Conditions | 30 |
Paths | 288 |
Total Lines | 112 |
Code Lines | 76 |
Lines | 16 |
Ratio | 14.29 % |
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 namespace EvolutionCMS\Legacy; |
||
67 | private function render($data) { |
||
68 | $modx = evolutionCMS(); global $_lang, $_country_lang; |
||
69 | |||
70 | $data['lang.name'] = (isset($_lang[$data['alias']]) ? $_lang[$data['alias']] : $data['alias']); |
||
71 | $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $_POST[$data['name']][$data['value']] : (isset($data['value']) ? $modx->htmlspecialchars($data['value']) : '')); |
||
72 | $data['readonly'] = ($data['readonly'] ? ' readonly' : ''); |
||
73 | |||
74 | $output = ''; |
||
75 | $output .= '<div class="form-group row">'; |
||
76 | |||
77 | switch($data['type']) { |
||
78 | |||
79 | case 'text': |
||
80 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
81 | <div class="col-sm-7"> |
||
82 | <input type="text" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
83 | $output .= $data['content']; |
||
84 | $output .= '</div>'; |
||
85 | |||
86 | break; |
||
87 | |||
88 | case 'textarea': |
||
89 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
90 | <div class="col-sm-7"> |
||
91 | <textarea name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;"[+readonly+]>[+value+]</textarea>'; |
||
92 | $output .= $data['content']; |
||
93 | $output .= '</div>'; |
||
94 | |||
95 | break; |
||
96 | |||
97 | case 'date': |
||
98 | $data['value'] = (isset($_POST[$data['name']][$data['value']]) ? $modx->toDateFormat($_POST[$data['name']][$data['value']]) : (isset($data['value']) ? $modx->toDateFormat($data['value']) : '')); |
||
99 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label> |
||
100 | <div class="col-sm-7"> |
||
101 | <input type="text" name="[+name+]" class="form-control DatePicker" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
102 | $output .= $data['content']; |
||
103 | $output .= '</div>'; |
||
104 | |||
105 | break; |
||
106 | |||
107 | case 'select': |
||
108 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
109 | $output .= '<div class="col-sm-7">'; |
||
110 | $output .= '<select name="[+name+]" class="form-control" id="[+name+]" onChange="documentDirty=true;">'; |
||
111 | if($data['name'] == 'country' && isset($_country_lang)) { |
||
112 | $chosenCountry = isset($_POST['country']) ? $_POST['country'] : $data['country']; |
||
113 | $output .= '<option value=""' . (!isset($chosenCountry) ? ' selected' : '') . '> </option>'; |
||
114 | foreach($_country_lang as $key => $value) { |
||
115 | $output .= '<option value="' . $key . '"' . (isset($chosenCountry) && $chosenCountry == $key ? ' selected' : '') . '>' . $value . '</option>'; |
||
116 | } |
||
117 | View Code Duplication | } else { |
|
118 | if($data['elements']) { |
||
119 | $elements = explode('||', $data['elements']); |
||
120 | foreach($elements as $key => $value) { |
||
121 | $value = explode('==', $value); |
||
122 | $output .= '<option value="' . $value[1] . '">' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]) . '</option>'; |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | $output .= '</select>'; |
||
127 | $output .= $data['content']; |
||
128 | $output .= '</div>'; |
||
129 | |||
130 | break; |
||
131 | |||
132 | case 'checkbox': |
||
133 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
134 | $output .= '<div class="col-sm-7">'; |
||
135 | $output .= '<input type="checkbox" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
136 | if($data['elements']) { |
||
137 | $elements = explode('||', $data['elements']); |
||
138 | foreach($elements as $key => $value) { |
||
139 | $value = explode('==', $value); |
||
140 | $output .= '<br /><input type="checkbox" name="' . $value[0] . '" class="form-control" id="' . $value[0] . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]); |
||
141 | } |
||
142 | } |
||
143 | $output .= $data['content']; |
||
144 | $output .= '</div>'; |
||
145 | |||
146 | break; |
||
147 | |||
148 | case 'radio': |
||
149 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
150 | $output .= '<div class="col-sm-7">'; |
||
151 | $output .= '<input type="radio" name="[+name+]" class="form-control" id="[+name+]" value="[+value+]" onChange="documentDirty=true;"[+readonly+] />'; |
||
152 | View Code Duplication | if($data['elements']) { |
|
153 | $elements = explode('||', $data['elements']); |
||
154 | foreach($elements as $key => $value) { |
||
155 | $value = explode('==', $value); |
||
156 | $output .= '<br /><input type="radio" name="[+name+]" class="form-control" id="[+name+]_' . $key . '" value="' . $value[1] . '" onChange="documentDirty=true;"[+readonly+] /> ' . (isset($_lang[$value[0]]) ? $_lang[$value[0]] : $value[0]); |
||
157 | } |
||
158 | } |
||
159 | $output .= $data['content']; |
||
160 | $output .= '</div>'; |
||
161 | |||
162 | break; |
||
163 | |||
164 | case 'custom': |
||
165 | $output .= '<label class="col-sm-3" for="[+name+]">[+lang.name+]</label>'; |
||
166 | $output .= '<div class="col-sm-7">'; |
||
167 | $output .= $data['content']; |
||
168 | $output .= '</div>'; |
||
169 | |||
170 | break; |
||
171 | } |
||
172 | |||
173 | $output .= '</div>'; |
||
174 | |||
175 | $output = $modx->parseText($output, $data); |
||
176 | |||
177 | return $output; |
||
178 | } |
||
179 | |||
181 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.