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

js/importers/importer-passpackcsv.js   A

Complexity

Total Complexity 9
Complexity/F 1.8

Size

Lines of Code 52
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 52
rs 10
wmc 9
mnd 3
bc 9
fnc 5
bpm 1.8
cpm 1.8
noi 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
B PassmanImporter.passpackCsv.readFile 0 39 1
A 0 51 1
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);