| Conditions | 1 |
| Paths | 2 |
| Total Lines | 53 |
| 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 | /** |
||
| 26 | (function (window, $, PassmanImporter) { |
||
| 27 | 'use strict'; |
||
| 28 | // Define the importer |
||
| 29 | PassmanImporter.keepassCsv = { |
||
| 30 | info: { |
||
| 31 | name: 'KeePass csv', |
||
| 32 | id: 'keepassCsv', |
||
| 33 | description: 'Create an csv export with the following options enabled: http://i.imgur.com/CaeTA4d.png' |
||
| 34 | } |
||
| 35 | }; |
||
| 36 | |||
| 37 | PassmanImporter.keepassCsv.readFile = function (file_data) { |
||
| 38 | /** global: C_Promise */ |
||
| 39 | var p = new C_Promise(function () { |
||
| 40 | var parsed_csv = PassmanImporter.readCsv(file_data); |
||
| 41 | var credential_list = []; |
||
| 42 | for (var i = 0; i < parsed_csv.length; i++) { |
||
| 43 | var row = parsed_csv[i]; |
||
| 44 | var _credential = PassmanImporter.newCredential(); |
||
| 45 | _credential.label = row.account; |
||
| 46 | _credential.username = row.login_name; |
||
| 47 | _credential.password = row.password; |
||
| 48 | _credential.url = row.web_site; |
||
| 49 | if (row.hasOwnProperty('expires')) { |
||
| 50 | row.expires = row.expires.replace('"', ''); |
||
| 51 | _credential.expire_time = new Date(row.expires).getTime() / 1000; |
||
| 52 | } |
||
| 53 | |||
| 54 | var tags = (row.group) ? [{text: row.group}] : []; |
||
| 55 | if (row.hasOwnProperty('group_tree')) { |
||
| 56 | var exploded_tree = row.group_tree.split('\\\\'); |
||
| 57 | for (var t = 0; t < exploded_tree.length; t++) { |
||
| 58 | if (exploded_tree[t].trim().length > 0) { |
||
| 59 | tags.push({text: exploded_tree[t].trim()}); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | _credential.tags = tags; |
||
| 64 | credential_list.push(_credential); |
||
| 65 | |||
| 66 | var progress = { |
||
| 67 | percent: i / parsed_csv.length * 100, |
||
| 68 | loaded: i, |
||
| 69 | total: parsed_csv.length |
||
| 70 | }; |
||
| 71 | |||
| 72 | this.call_progress(progress); |
||
| 73 | } |
||
| 74 | this.call_then(credential_list); |
||
| 75 | }); |
||
| 76 | return p; |
||
| 77 | }; |
||
| 78 | })(window, $, PassmanImporter); |
||
| 79 |