Conditions | 23 |
Paths | > 20000 |
Total Lines | 86 |
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:
Complex classes like supercheckout.js ➔ fill_the_form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | /** |
||
26 | function fill_the_form(){ |
||
27 | firstname_input = document.getElementsByName("payment_address[firstname]"); |
||
|
|||
28 | billing_firstname = ''; |
||
29 | if (firstname_input.length > 0){ |
||
30 | billing_firstname = firstname_input[0].value; |
||
31 | } |
||
32 | billing_lastname = ''; |
||
33 | lastname_input = document.getElementsByName("payment_address[lastname]"); |
||
34 | if (lastname_input.length > 0){ |
||
35 | billing_lastname = lastname_input[0].value; |
||
36 | } |
||
37 | shipping_firstname = ''; |
||
38 | firstname_input = document.getElementsByName("shipping_address[firstname]"); |
||
39 | if (firstname_input.length > 0){ |
||
40 | shipping_firstname = firstname_input[0].value; |
||
41 | } |
||
42 | shipping_lastname = ''; |
||
43 | lastname_input = document.getElementsByName("shipping_address[lastname]"); |
||
44 | if (lastname_input.length > 0){ |
||
45 | shipping_lastname = lastname_input[0].value; |
||
46 | } |
||
47 | email = ''; |
||
48 | email_input = document.getElementsByName("supercheckout_email"); |
||
49 | if (email_input.length > 0){ |
||
50 | email = email_input[0].value; |
||
51 | } |
||
52 | billing_name = billing_firstname + " " + billing_lastname; |
||
53 | shipping_name = shipping_firstname + " " + shipping_lastname; |
||
54 | if (document.getElementById("paylater_full_name").value.trim() == '') { |
||
55 | if (billing_name.trim() != '') { |
||
56 | document.getElementById("paylater_full_name").value = billing_name; |
||
57 | } else if (shipping_name.trim() != '') { |
||
58 | document.getElementById("paylater_full_name").value = shipping_name; |
||
59 | } |
||
60 | } |
||
61 | if (document.getElementById("paylater_email").value.trim() == '') { |
||
62 | document.getElementById("paylater_email").value = email; |
||
63 | } |
||
64 | dni = ''; |
||
65 | dni_input = document.getElementsByName("shipping_address[dni]"); |
||
66 | if (dni_input.length > 0){ |
||
67 | dni = dni_input[0].value; |
||
68 | } |
||
69 | if (document.getElementById("paylater_full_name") == document.getElementsByName("shipping[full_name]")[0].value ) { |
||
70 | if (document.getElementById("paylater_dni").value.trim() != '') { |
||
71 | document.getElementById("paylater_dni").value = dni; |
||
72 | } |
||
73 | } |
||
74 | saddress1 = document.getElementsByName("shipping_address[address1]"); |
||
75 | saddress2 = document.getElementsByName("shipping_address[address2]"); |
||
76 | sa1 = ''; |
||
77 | sa2 = ''; |
||
78 | if (saddress1.length > 0){ |
||
79 | sa1 = saddress1[0].value; |
||
80 | } |
||
81 | if (saddress2.length > 0){ |
||
82 | sa2 = saddress2[0].value; |
||
83 | } |
||
84 | saddress = sa1 + " " + sa1; |
||
85 | |||
86 | address1 = document.getElementsByName("payment_address[address1]"); |
||
87 | address2 = document.getElementsByName("payment_address[address2]"); |
||
88 | a1 = ''; |
||
89 | a2 = ''; |
||
90 | if (address1.length > 0){ |
||
91 | a1 = address1[0].value; |
||
92 | } |
||
93 | if (address2.length > 0){ |
||
94 | a2 = address2[0].value; |
||
95 | } |
||
96 | address = sa1 + " " + sa1; |
||
97 | if (document.getElementsByName("shipping[full_name]")[0].value.trim() == '') { |
||
98 | document.getElementsByName("shipping[full_name]")[0].value = saddress; |
||
99 | } |
||
100 | if (document.getElementsByName("billing[full_name]")[0].value.trim() == '') { |
||
101 | document.getElementsByName("billing[full_name]")[0].value = address; |
||
102 | } |
||
103 | dob_1 = document.getElementsByName("customer_personal[dob_days]"); |
||
104 | dob_2 = document.getElementsByName("customer_personal[dob_months]"); |
||
105 | dob_3 = document.getElementsByName("customer_personal[dob_years]"); |
||
106 | if (dob_1.length > 0 && dob_2.length > 0 && dob_3.length > 0){ |
||
107 | if (document.getElementById("paylater_dob").value.trim() == '') { |
||
108 | document.getElementById("paylater_dob").value = dob_3[0].value + "-" + dob_2[0].value + "-" + dob_1[0].value; |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 | function check_pagantis_ready(){ |
||
133 |