Conditions | 21 |
Paths | 26 |
Total Lines | 74 |
Code Lines | 71 |
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 ipcRenderer.bw:status.update 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 | var whois = require('../../common/whoiswrapper.js'), |
||
44 | ipcRenderer.on('bw:status.update', function(event, stat, value) { |
||
45 | ipcRenderer.send('app:debug', "{0}, value update to {1}".format(stat, value)); // status update |
||
46 | var percent; |
||
47 | switch (stat) { |
||
48 | case 'start': |
||
49 | if ($('#bwpButtonNext').hasClass('is-hidden') === false) { |
||
50 | $('#bwpButtonNext').addClass('is-hidden'); |
||
51 | $('#bwpButtonPause').removeClass('is-hidden'); |
||
52 | $('#bwpButtonStop').removeClass('is-hidden'); |
||
53 | } |
||
54 | break; |
||
55 | case 'domains.processed': // processed domains |
||
56 | percent = parseFloat((value / parseInt($('#bwTableProcessingTotal').text(), base) * 100).toFixed(1)) || 0; |
||
57 | $('#bwTableProcessingProcessed').text('{0} ({1}%)'.format(value, percent)); |
||
58 | break; |
||
59 | case 'domains.waiting': // whois requests waiting reply |
||
60 | percent = parseFloat((value / parseInt($('#bwTableProcessingSent').text(), base) * 100).toFixed(1)) || 0; |
||
61 | $('#bwTableProcessingWaiting').text('{0} ({1}%)'.format(value, percent)); |
||
62 | break; |
||
63 | case 'domains.sent': // sent whois requests |
||
64 | percent = parseFloat((value / parseInt($('#bwTableProcessingTotal').text(), base) * 100).toFixed(1)) || 0; |
||
65 | $('#bwTableProcessingSent').text('{0} ({1}%)'.format(value, percent)); |
||
66 | break; |
||
67 | case 'domains.total': // total domains |
||
68 | $('#bwTableProcessingTotal').text(value); |
||
69 | break; |
||
70 | case 'time.current': // current time |
||
71 | $('#bwTableProcessingCurrentTime').text('{0}'.format(value)); |
||
72 | break; |
||
73 | case 'time.remaining': // remaining time |
||
74 | $('#bwTableProcessingRemainingTime').text('{0}'.format(value)); |
||
75 | break; |
||
76 | case 'reqtimes.maximum': // maximum request reply time |
||
77 | $('#bwTableProcessingReqMax').text('{0}ms'.format(value)); |
||
78 | break; |
||
79 | case 'reqtimes.minimum': // minimum request reply time |
||
80 | $('#bwTableProcessingReqMin').text('{0}ms'.format(value)); |
||
81 | break; |
||
82 | case 'reqtimes.last': // last request reply time |
||
83 | $('#bwTableProcessingReqLast').text('{0}ms'.format(value)); |
||
84 | break; |
||
85 | case 'reqtimes.average': // Average request reply time |
||
86 | $('#bwTableProcessingReqAvg').text('{0}ms'.format(value)); |
||
87 | break; |
||
88 | case 'status.available': // Domains available |
||
89 | percent = parseFloat((value / parseInt($('#bwTableProcessingTotal').text(), base) * 100).toFixed(1)) || 0; |
||
90 | $('#bwTableProcessingDomAvail').text('{0} ({1}%)'.format(value, percent)); |
||
91 | break; |
||
92 | case 'status.unavailable': // Domains unavailable |
||
93 | percent = parseFloat((value / parseInt($('#bwTableProcessingTotal').text(), base) * 100).toFixed(1)) || 0; |
||
94 | $('#bwTableProcessingDomUnavail').text('{0} ({1}%)'.format(value, percent)); |
||
95 | break; |
||
96 | case 'status.error': // Domains error |
||
97 | percent = parseFloat((value / parseInt($('#bwTableProcessingTotal').text(), base) * 100).toFixed(1)) || 0; |
||
98 | $('#bwTableProcessingDomError').text('{0} ({1}%)'.format(value, percent)); |
||
99 | break; |
||
100 | case 'laststatus.available': // Last available domain |
||
101 | $('#bwTableProcessingLastDomAvail').text('{0}'.format(value)); |
||
102 | break; |
||
103 | case 'laststatus.unavailable': // Last unavailable domain |
||
104 | $('#bwTableProcessingLastDomUnavail').text('{0}'.format(value)); |
||
105 | break; |
||
106 | case 'laststatus.error': // Last error domain |
||
107 | $('#bwTableProcessingLastDomError').text('{0}'.format(value)); |
||
108 | break; |
||
109 | case 'finished': // Finished |
||
110 | $('#bwpButtonPause').addClass('is-hidden'); |
||
111 | $('#bwpButtonStop').addClass('is-hidden'); |
||
112 | $('#bwpButtonNext').removeClass('is-hidden'); |
||
113 | break; |
||
114 | default: |
||
115 | break; |
||
116 | } |
||
117 | }); |
||
118 | |||
181 |