Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
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 | // Importers should always start with this |
||
3 | (function(window, $, PassmanImporter) { |
||
4 | 'use strict'; |
||
5 | // Define the importer |
||
6 | PassmanImporter.passpackCsv = { |
||
7 | info: { |
||
8 | name: 'Passpack csv', |
||
9 | id: 'passpackCsv', |
||
10 | description: 'Go to Tools -> Export. Select Comma Separated Values, All entries then continue.' |
||
11 | } |
||
12 | }; |
||
13 | |||
14 | PassmanImporter.passpackCsv.readFile = function (file_data) { |
||
15 | return new C_Promise(function(){ |
||
16 | var parsed_csv = PassmanImporter.readCsv(file_data, false); |
||
17 | var credential_list = []; |
||
18 | for (var i = 0; i < parsed_csv.length; i++) { |
||
19 | var row = parsed_csv[i]; |
||
20 | var _credential = PassmanImporter.newCredential(); |
||
21 | _credential.label = row[0]; |
||
22 | _credential.username = row[1]; |
||
23 | _credential.password = row[2]; |
||
24 | _credential.url = row[3]; |
||
25 | var tags = row[4].split(' '); |
||
26 | if (tags.length > 0) { |
||
27 | _credential.tags = tags.map(function (item) { |
||
28 | if (item) { |
||
29 | return {text: item} |
||
30 | } |
||
31 | |||
32 | }).filter(function (item) { |
||
33 | return (item); |
||
34 | }); |
||
35 | } |
||
36 | _credential.description = row[5]; |
||
37 | _credential.email = row[6]; |
||
38 | if (_credential.label) { |
||
39 | credential_list.push(_credential); |
||
40 | } |
||
41 | |||
42 | var progress = { |
||
43 | percent: i/parsed_csv.length*100, |
||
44 | loaded: i, |
||
45 | total: parsed_csv.length |
||
46 | }; |
||
47 | |||
48 | this.call_progress(progress); |
||
49 | } |
||
50 | this.call_then(credential_list); |
||
51 | }) |
||
52 | }; |
||
53 | })(window, $, PassmanImporter); |