Conditions | 6 |
Paths | 5 |
Total Lines | 67 |
Code Lines | 46 |
Lines | 67 |
Ratio | 100 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 | /** global: appSettings */ |
||
15 | View Code Duplication | ipcRenderer.on('bwa:fileinput.confirmation', function(event, filePath = null, isDragDrop = false) { |
|
16 | const { |
||
17 | misc, |
||
18 | lookup |
||
19 | } = appSettings; |
||
20 | var bwFileStats; // File stats, size, last changed, etc |
||
21 | |||
22 | //console.log(filePath); |
||
23 | if (filePath === undefined || filePath == '' || filePath === null) { |
||
24 | //console.log(filePath); |
||
25 | $('#bwaFileInputLoading').addClass('is-hidden'); |
||
26 | $('#bwaEntry').removeClass('is-hidden'); |
||
27 | } else { |
||
28 | $('#bwLoadingInfo').text('Loading file stats...'); |
||
29 | if (isDragDrop === true) { |
||
30 | $('#bwEntry').addClass('is-hidden'); |
||
31 | $('#bwFileInputLoading').removeClass('is-hidden'); |
||
32 | bwFileStats = fs.statSync(filePath); |
||
33 | bwFileStats['filename'] = filePath.replace(/^.*[\\\/]/, ''); |
||
34 | bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
||
35 | $('#bwfLoadingInfo').text('Loading file contents...'); |
||
36 | bwFileContents = fs.readFileSync(filePath); |
||
37 | } else { |
||
38 | bwFileStats = fs.statSync(filePath[0]); |
||
39 | bwFileStats['filename'] = filePath[0].replace(/^.*[\\\/]/, ''); |
||
40 | bwFileStats['humansize'] = conversions.byteToHumanFileSize(bwFileStats['size'], misc.usestandardsize); |
||
41 | $('#bwfLoadingInfo').text('Loading file contents...'); |
||
42 | bwFileContents = fs.readFileSync(filePath[0]); |
||
43 | } |
||
44 | $('#bwfLoadingInfo').text('Getting line count...'); |
||
45 | bwFileStats['linecount'] = bwFileContents.toString().split('\n').length; |
||
46 | |||
47 | if (lookup.randomize.timebetween === true) { |
||
48 | bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmin); |
||
49 | bwFileStats['maxestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.randomize.timebetweenmax); |
||
50 | $('#bwftimebetweenmin').text('{0}ms '.format(lookup.randomize.timebetweenmin)); |
||
51 | $('#bwftimebetweenmax').text('/ {0}ms'.format(lookup.randomize.timebetweenmax)); |
||
52 | $('#bwfTableMinMaxEstimate').text('{0} to {1}'.format(bwFileStats['minestimate'], bwFileStats['maxestimate'])); |
||
53 | } else { |
||
54 | bwFileStats['minestimate'] = conversions.msToHumanTime(bwFileStats['linecount'] * lookup.timebetween); |
||
55 | $('#bwftimebetweenmaxtext').addClass('is-hidden'); |
||
56 | $('#bwftimebetweenmin').text(lookup.timebetween + 'ms'); |
||
57 | $('#bwfTableMinMaxEstimate').text('> {0}'.format(bwFileStats['minestimate'])); |
||
58 | } |
||
59 | |||
60 | |||
61 | |||
62 | bwFileStats['filepreview'] = bwFileContents.toString().substring(0, 50); |
||
63 | //console.log(readLines(filePath[0])); |
||
64 | //console.log(bwFileStats['filepreview']); |
||
65 | |||
66 | //console.log(lineCount(bwFileContents)); |
||
67 | $('#bwFileInputLoading').addClass('is-hidden'); |
||
68 | $('#bwFileInputConfirm').removeClass('is-hidden'); |
||
69 | |||
70 | // stats |
||
71 | $('#bwfTableFilename').text(bwFileStats['filename']); |
||
72 | $('#bwfTableFileLastModified').text(bwFileStats['mtime']); |
||
73 | $('#bwfTableFileLastAccessed').text(bwFileStats['atime']); |
||
74 | $('#bwfTableFileSize').text(bwFileStats['humansize'] + ' ({0} line(s))'.format(bwFileStats['linecount'])); |
||
75 | $('#bwfTableFilePreview').text(bwFileStats['filepreview'] + '...'); |
||
76 | //$('#bwTableMaxEstimate').text(bwFileStats['maxestimate']); |
||
77 | //console.log('cont:'+ bwFileContents); |
||
78 | |||
79 | //console.log(bwFileStats['linecount']); |
||
80 | } |
||
81 | }); |
||
82 | |||
145 |