rest/rest-module.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 2

Size

Lines of Code 50
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 26
mnd 4
bc 4
fnc 4
dl 0
loc 50
rs 10
bpm 1
cpm 2
noi 5
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A rest-module.js ➔ formData 0 19 2
1
// formToObject
2
// Rest
3
function restModule(modulename, classname_prefix, domain, restfile, error, success) {
4
5
    if (classname_prefix === undefined || classname_prefix.length < 1) {
6
        classname_prefix = 'module-';
7
    }
8
9
    if (domain === undefined || domain.length < 1) {
10
        domain = '/visitor/';
11
    }
12
13
    if (restfile === undefined || restfile.length < 1) {
14
        restfile = '/php/index.php';
15
    }
16
17
    var url = domain + modulename + restfile;
18
19
    var rest_form = new Rest(url, '?', error, success);
0 ignored issues
show
Bug introduced by
The variable Rest seems to be never declared. If this is a global, consider adding a /** global: Rest */ 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...
20
21
22
    // var forms = document.getElementsByTagName('form');
23
    var testElements = document.getElementsByClassName(classname_prefix + modulename);
24
    var forms = Array.prototype.filter.call(testElements, function (testElement) {
25
        return testElement.nodeName === 'FORM';
26
    });
27
28
    // console.log(forms);
29
    for (var i = 0; i < forms.length; i++) {
30
        formData(forms[i], rest_form, error, success);
31
    }
32
}
33
34
function formData(form, rest_form, error, success) {
0 ignored issues
show
Unused Code introduced by
The parameter success is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter error is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
35
    console.log(form);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
36
37
    form.addEventListener("submit", function (event) {
38
        console.log(this);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
39
40
        var data = formToObject(this);
41
        var method = data.method;
42
        delete data.method;
43
        delete data.submit;
44
45
        console.log(method);
46
47
        rest_form.byMethod(method, data);
48
        console.log(data);
49
50
        event.preventDefault();
51
    });
52
}
53