| Conditions | 8 |
| Paths | 28 |
| Total Lines | 74 |
| 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 | /** |
||
| 59 | function ratepayRateCalculatorAction(mode, paymentMethod, url) |
||
| 60 | { |
||
| 61 | var calcValue, |
||
| 62 | calcMethod, |
||
| 63 | notification, |
||
| 64 | html, |
||
| 65 | ratePayshopId, |
||
| 66 | amount, |
||
| 67 | ratePayCurrency, |
||
| 68 | ajaxLoader = $("ajaxLoaderId"), |
||
| 69 | cover = $("cover"); |
||
| 70 | |||
| 71 | ajaxLoader.setStyle({ |
||
| 72 | display: 'block' |
||
| 73 | }); |
||
| 74 | cover.setStyle({ |
||
| 75 | display: 'block' |
||
| 76 | }); |
||
| 77 | |||
| 78 | |||
| 79 | if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari |
||
| 80 | xmlhttp = new XMLHttpRequest(); |
||
| 81 | } else {// code for IE6, IE5 |
||
| 82 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); |
||
| 83 | } |
||
| 84 | amount = document.getElementById('amount').value; |
||
| 85 | ratePayshopId = document.getElementById('ratePayShopId').value; |
||
| 86 | ratePayCurrency = document.getElementById('ratePayCurrency').value; |
||
| 87 | if (mode == 'rate') { |
||
| 88 | calcValue = document.getElementById(paymentMethod + '-rate').value; |
||
| 89 | |||
| 90 | |||
| 91 | calcMethod = 'calculation-by-rate'; |
||
| 92 | if (document.getElementById('debitSelect')) { |
||
| 93 | dueDate = document.getElementById('debitSelect').value; |
||
| 94 | } else { |
||
| 95 | dueDate= ''; |
||
| 96 | } |
||
| 97 | } else if (mode == 'runtime') { |
||
| 98 | calcValue = document.getElementById(paymentMethod + '-runtime').value; |
||
| 99 | calcMethod = 'calculation-by-time'; |
||
| 100 | notification = (document.getElementById(paymentMethod + '_Notification') == null) ? 0 : 1; |
||
| 101 | if(document.getElementById('debitSelectRuntime')){ |
||
| 102 | dueDate = document.getElementById('debitSelectRuntime').value; |
||
| 103 | } else { |
||
| 104 | dueDate= ''; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | xmlhttp.open("POST", url, false); |
||
| 108 | |||
| 109 | xmlhttp.setRequestHeader("Content-Type", |
||
| 110 | "application/x-www-form-urlencoded"); |
||
| 111 | |||
| 112 | xmlhttp.send("paymentMethod=" + paymentMethod + "&calcValue=" + calcValue + "&calcMethod=" + calcMethod + "&dueDate=" + dueDate |
||
| 113 | + "¬ification=" + notification |
||
| 114 | + "&ratePayshopId=" + ratePayshopId + "&ratePayCurrency=" + ratePayCurrency + "&amount=" + amount |
||
| 115 | ); |
||
| 116 | |||
| 117 | if (xmlhttp.responseText != null) { |
||
| 118 | html = xmlhttp.responseText; |
||
| 119 | document.getElementById(paymentMethod + '_ResultContainer').innerHTML = html; |
||
| 120 | document.getElementById(paymentMethod + '_ResultContainer').style.display = 'block'; |
||
| 121 | document.getElementById(paymentMethod + '_ResultContainer').style.padding = '3px 0 0 0'; |
||
| 122 | document.getElementById(paymentMethod + '_SwitchToTerm').style.display = 'none'; |
||
| 123 | |||
| 124 | ajaxLoader.setStyle({ |
||
| 125 | display: 'none' |
||
| 126 | }); |
||
| 127 | cover.setStyle({ |
||
| 128 | display: 'none' |
||
| 129 | }); |
||
| 130 | } |
||
| 131 | |||
| 132 | } |
||
| 133 | /** |
||
| 184 | }); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.