e.js   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 2.33

Size

Lines of Code 79
Function Count 6

Duplication

Duplicated Lines 79
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 14
eloc 48
mnd 8
bc 8
fnc 6
dl 79
loc 79
rs 10
bpm 1.3333
cpm 2.3333
noi 4
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
// var HomeMessage = function (name, success, error) {
2
//     this.name = name;
3
//     this.success = success;
4
//     this.error = error;
5
//
6
//     this.create = function (data) {
7
//         restSubmit(this.name, 'GET', data, this.success, this.error);
8
//     }
9
//
10
// };
11
12
// example: element('body').first().
13
14 View Code Duplication
var E = function (selector, area, error, success) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
    this.cfg = {};
16
    this.cfg.area = document;
17
    this.cfg.selector = selector;
18
    this.cfg.exist = false;
19
20
    this.success = function (elem) {
21
        console.log("Element elem: ", elem);
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...
22
    };
23
24
    this.error = function (elem) {
25
        console.error("! Element elem: ", elem);
26
    };
27
28
    if (typeof success === 'function') {
29
        this.success = success;
30
    }
31
32
    if (typeof error === 'function') {
33
        this.error = error;
34
    }
35
36
37
    var self = this;
38
39
    this.selector = function (selector) {
40
        self.cfg.selector = selector;
41
        return this;
42
    }
43
44
    this.first = function (error, success) {
45
        if (typeof success !== 'function') {
46
            success = self.success;
47
        }
48
        if (typeof error !== 'function') {
49
            error = self.error;
50
        }
51
52
        const elem = document.querySelector(self.cfg.selector);
53
54
        console.log('E first self.cfg.selector', self.cfg.selector);
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...
55
        console.log('E first elem', elem);
56
57
        if (elem !== null) {
58
            self.cfg.exist = true;
59
            success(elem);
60
            return elem;
61
        } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
62
            self.cfg.exist = false;
63
            error();
64
        }
65
66
        return elem;
67
    }
68
69
    this.all = function (error, success) {
70
        if (typeof success !== 'function') {
71
            success = self.success;
72
        }
73
        if (typeof error !== 'function') {
74
            error = self.error;
75
        }
76
77
        const elem = document.querySelectorAll(self.cfg.selector);
78
79
        console.log('E all self.cfg.selector', self.cfg.selector);
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...
80
        console.log('E all elem', elem);
81
82
        if (elem !== null) {
83
            self.cfg.exist = true;
84
            success(elem);
85
        } else {
86
            self.cfg.exist = false;
87
            error(elem);
88
        }
89
90
        return elem;
91
    }
92
};
93
94
//
95
// function getElement(id) {
96
//     if (document.getElementById) {
97
//         return document.getElementById(id);
98
//     } else if (document.all) {
99
//         return window.document.all[id];
100
//     } else if (document.layers) {
101
//         return window.document.layers[id];
102
//     }
103
// }
104
//
105
// function getElement() {
106
//     const element = document.querySelector("#box");
107
//
108
//     element.classList.contains("highlighted");
109
//
110
//     return element;
111
// }
112
//
113
//
114
// function getElement() {
115
//     const element = document.querySelector("#box");
116
//
117
//     element.classList.contains("highlighted");
118
//
119
//     return element;
120
// }
121