| Conditions | 12 |
| Paths | 44 |
| Total Lines | 202 |
| 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 |
||
| 144 | protected function getInput() |
||
| 145 | { |
||
| 146 | // Set the class for the label. |
||
| 147 | $class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; |
||
| 148 | $istranslation = (int) $this->element['istranslation']; |
||
| 149 | $istextchange = (int) $this->element['istextchange']; |
||
| 150 | $isextraindev = (int) $this->element['isextraindev']; |
||
| 151 | $status = (string) $this->element['status']; |
||
| 152 | |||
| 153 | $label_id = $this->id . '-lbl'; |
||
| 154 | $label_for = $this->id; |
||
| 155 | $textarea_name = $this->name; |
||
| 156 | $textarea_id = $this->id; |
||
| 157 | $id = $this->id; |
||
| 158 | |||
| 159 | if ($istranslation == '1') |
||
| 160 | { |
||
| 161 | // If a description is specified, use it to build a tooltip. |
||
| 162 | if (!empty($this->descText)) |
||
| 163 | { |
||
| 164 | $label = '<label id="' . $label_id . '-lbl" for="' . $label_for . '" class="' . $class . '" title="' |
||
| 165 | . htmlspecialchars(htmlspecialchars('::' . str_replace("\n", "\\n", $this->descText), ENT_QUOTES, 'UTF-8')) . '">'; |
||
| 166 | } |
||
| 167 | else |
||
| 168 | { |
||
| 169 | $label = '<label id="' . $label_id . '-lbl" for="' . $label_for . '" class="' . $class . '">'; |
||
| 170 | } |
||
| 171 | |||
| 172 | JText::script('COM_LOCALISE_LABEL_TRANSLATION_GOOGLE_ERROR'); |
||
| 173 | |||
| 174 | $label .= $this->element['label'] . '<br />' . (string) $this->element['description']; |
||
| 175 | $label .= '</label>'; |
||
| 176 | |||
| 177 | $onclick = ''; |
||
| 178 | $button = ''; |
||
| 179 | |||
| 180 | $onclick2 = ''; |
||
| 181 | $button2 = ''; |
||
| 182 | |||
| 183 | if ($status == 'extra') |
||
| 184 | { |
||
| 185 | $onclick = ''; |
||
| 186 | $button = '<span style="width:5%;">' |
||
| 187 | . JHtml::_('image', 'com_localise/icon-16-arrow-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
||
| 188 | |||
| 189 | $onclick2 = ''; |
||
| 190 | $button2 = '<span style="width:5%;">' |
||
| 191 | . JHtml::_('image', 'com_localise/icon-16-bing-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
||
| 192 | $input = ''; |
||
| 193 | $input .= '<textarea name="' . $textarea_name; |
||
| 194 | $input .= '" id="' . $textarea_id . '" class="width-45 ' . $status . ' ">'; |
||
| 195 | $input .= htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>'; |
||
| 196 | } |
||
| 197 | else |
||
| 198 | { |
||
| 199 | $token = JSession::getFormToken(); |
||
| 200 | |||
| 201 | $onclick = ""; |
||
| 202 | $onclick .= "javascript:document.id('" . $id . "').set('value','"; |
||
| 203 | $onclick .= addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')); |
||
| 204 | $onclick .= "');"; |
||
| 205 | $onclick .= "document.id('" . $id . "').set('class','width-45 untranslated');"; |
||
| 206 | |||
| 207 | $onclick2 = "javascript:AzureTranslator(this, [], 0, '$token');"; |
||
| 208 | |||
| 209 | $button = ''; |
||
| 210 | $button .= '<i class="icon-reset hasTooltip return pointer" title="'; |
||
| 211 | $button .= JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_INSERT'); |
||
| 212 | $button .= '" onclick="' . $onclick . '"></i>'; |
||
| 213 | |||
| 214 | $button2 = ''; |
||
| 215 | $button2 .= '<input type="hidden" id="' . $id . 'text" value=\''; |
||
| 216 | $button2 .= addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) . '\' />'; |
||
| 217 | $button2 .= '<i class="icon-translate-bing hasTooltip translate pointer" title="'; |
||
| 218 | $button2 .= JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_AZURE'); |
||
| 219 | $button2 .= '" onclick="' . $onclick2 . '" rel="' . $id . '"></i>'; |
||
| 220 | |||
| 221 | $onkeyup = "javascript:"; |
||
| 222 | |||
| 223 | if ($istextchange == 1) |
||
| 224 | { |
||
| 225 | $onkeyup .= "if (this.get('value')=='') |
||
| 226 | { |
||
| 227 | this.set('class','width-45 untranslated'); |
||
| 228 | } |
||
| 229 | else if (this.get('value')=='" |
||
| 230 | . addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) |
||
| 231 | . "') |
||
| 232 | { |
||
| 233 | this.set('class','width-45 untranslated'); |
||
| 234 | } |
||
| 235 | else if (this.get('value')=='" |
||
| 236 | . addslashes(htmlspecialchars($this->element['frozen_task'], ENT_COMPAT, 'UTF-8')) |
||
| 237 | . "') |
||
| 238 | { |
||
| 239 | this.set('class','width-45 untranslated'); |
||
| 240 | } |
||
| 241 | else |
||
| 242 | { |
||
| 243 | this.set('class','width-45 translated'); |
||
| 244 | }"; |
||
| 245 | } |
||
| 246 | else |
||
| 247 | { |
||
| 248 | $onkeyup .= "if (this.get('value')=='') |
||
| 249 | { |
||
| 250 | this.set('class','width-45 untranslated'); |
||
| 251 | } |
||
| 252 | else if (this.get('value')=='" |
||
| 253 | . addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) |
||
| 254 | . "') |
||
| 255 | { |
||
| 256 | this.set('class','width-45 untranslated'); |
||
| 257 | } |
||
| 258 | else |
||
| 259 | { |
||
| 260 | this.set('class','width-45 translated'); |
||
| 261 | }"; |
||
| 262 | } |
||
| 263 | |||
| 264 | $onfocus = "javascript:this.select();"; |
||
| 265 | |||
| 266 | $input = ''; |
||
| 267 | $input .= '<textarea name="' . $textarea_name . '" id="' . $textarea_id . '" onfocus="' . $onfocus; |
||
| 268 | $input .= '" class="width-45 ' . $status . '" onkeyup="'; |
||
| 269 | $input .= $onkeyup . '">' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '</textarea>'; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | else |
||
| 273 | { |
||
| 274 | // Set the class for the label. |
||
| 275 | $class = !empty($this->descText) ? 'key-label hasTooltip fltrt' : 'key-label fltrt'; |
||
| 276 | |||
| 277 | // If a description is specified, use it to build a tooltip. |
||
| 278 | if (!empty($this->descText)) |
||
| 279 | { |
||
| 280 | $label = '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '" title="' |
||
| 281 | . htmlspecialchars(htmlspecialchars('::' . str_replace("\n", "\\n", $this->descText), ENT_QUOTES, 'UTF-8')) . '">'; |
||
| 282 | } |
||
| 283 | else |
||
| 284 | { |
||
| 285 | $label = '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '">'; |
||
| 286 | } |
||
| 287 | |||
| 288 | JText::script('COM_LOCALISE_LABEL_TRANSLATION_GOOGLE_ERROR'); |
||
| 289 | $label .= $this->element['label'] . '<br />' . $this->element['description']; |
||
| 290 | $label .= '</label>'; |
||
| 291 | |||
| 292 | // Adjusting the stuff when all them are reference keys. |
||
| 293 | $readonly = ''; |
||
| 294 | $textvalue = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); |
||
| 295 | |||
| 296 | if ($istextchange == 1 || $isextraindev == 1) |
||
| 297 | { |
||
| 298 | // There is no translation task in develop for the reference files in develop. |
||
| 299 | $readonly = ' readonly="readonly" '; |
||
| 300 | $textvalue = htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8'); |
||
| 301 | } |
||
| 302 | |||
| 303 | $status = (string) $this->element['status']; |
||
| 304 | |||
| 305 | $onclick = "javascript:document.id( |
||
| 306 | '" . $this->id . "' |
||
| 307 | ) |
||
| 308 | .set( |
||
| 309 | 'value','" . addslashes(htmlspecialchars($this->element['description'], ENT_COMPAT, 'UTF-8')) . "' |
||
| 310 | ); |
||
| 311 | if (document.id('" . $this->id . "').get('value')=='') {document.id('" . $this->id . "').set('class','width-45 untranslated');} |
||
| 312 | else {document.id('" . $this->id . "').set('class','width-45 " . $status . "');}"; |
||
| 313 | $button = '<i class="icon-reset hasTooltip return pointer" |
||
| 314 | title="' . JText::_('COM_LOCALISE_TOOLTIP_TRANSLATION_INSERT') . '" |
||
| 315 | onclick="' . $onclick . '"></i>'; |
||
| 316 | |||
| 317 | // No sense translate the reference keys by the same language. |
||
| 318 | $onclick2 = ''; |
||
| 319 | $button2 = '<span style="width:5%;">' |
||
| 320 | . JHtml::_('image', 'com_localise/icon-16-bing-gray.png', '', array('class' => 'pointer'), true) . '</span>'; |
||
| 321 | |||
| 322 | if ($istextchange == 1 || $isextraindev == 1) |
||
| 323 | { |
||
| 324 | // Is read only, so no changes. |
||
| 325 | $onkeyup = ""; |
||
| 326 | } |
||
| 327 | else |
||
| 328 | { |
||
| 329 | $onkeyup = "javascript:"; |
||
| 330 | $onkeyup .= "if (this.get('value')=='') {this.set('class','width-45 untranslated');} |
||
| 331 | else {if (this.get('value')=='" . addslashes(htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8')) |
||
| 332 | . "') this.set('class','width-45 " . $status . "'); |
||
| 333 | " . "else this.set('class','width-45 translated');}"; |
||
| 334 | } |
||
| 335 | |||
| 336 | $input = ''; |
||
| 337 | $input .= '<textarea name="' . $this->name . '" id="'; |
||
| 338 | $input .= $this->id . '"' . $readonly . ' onfocus="this.select()" class="width-45 '; |
||
| 339 | $input .= $status; |
||
| 340 | $input .= '" onkeyup="' . $onkeyup . '">' . $textvalue; |
||
| 341 | $input .= '</textarea>'; |
||
| 342 | } |
||
| 343 | |||
| 344 | return $button . $button2 . $input; |
||
| 345 | } |
||
| 346 | } |
||
| 347 |
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.