Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

js/importers/importer-passpackcsv.js   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 51
rs 9.4109

1 Function

Rating   Name   Duplication   Size   Complexity  
B PassmanImporter.passpackCsv.readFile 0 39 1

How to fix   Long Method   

Long Method

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:

1
// Importers should always start with this
2
var PassmanImporter = PassmanImporter || {};
1 ignored issue
show
Bug introduced by
The variable PassmanImporter seems to be never initialized.
Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
		return new C_Promise(function(){
0 ignored issues
show
Bug introduced by
The variable C_Promise seems to be never declared. If this is a global, consider adding a /** global: C_Promise */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if item is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
29
							return {text: item}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
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
		})
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
52
	};
53
})(window, $, PassmanImporter);