src/components/Debug/Exceptions/Resources/js/debug.base.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 2.4

Size

Lines of Code 67
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 37
c 0
b 0
f 0
dl 0
loc 67
rs 10
wmc 12
mnd 7
bc 7
fnc 5
bpm 1.4
cpm 2.4
noi 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A debug.base.js ➔ selectFrameInfo 0 12 3
A debug.base.js ➔ changeTo 0 8 5
1
(function(d)
2
{
3
    /* IE8 Incompatibility crap */
4
    var elements = ['section', 'header', 'footer'];
5
6
    for (let i = 0; i < elements.length; i++)
7
    {
8
        d.createElement(elements[i]);
9
    }
10
11
    var previousFrame = null;
12
    var previousInfo  = null;
13
    var allFrames     = d.querySelectorAll('.frame');
14
    var allFramesCode = d.querySelectorAll('.code-source');
15
    let evento        = ((document.ontouchstart !== null) ? 'mouseup' : 'touchstart');
16
17
    function changeTo(el) 
18
    {
19
        if (previousInfo) previousInfo.classList.remove("active");
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
21
        previousInfo = el;
22
23
        el.classList.add("active");
24
    }
25
26
    function selectFrameInfo(index)
27
    {
28
        var el = allFramesCode[index];
29
30
        if (el)
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el 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...
31
        {
32
            if (el.closest('[data-frame]'))
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if el.closest("[data-frame]") 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...
33
            {
34
                return changeTo(el);
35
            }
36
        }
37
    }
38
39
    for (let i = 0; i < allFrames.length; i++)
40
    {
41
        (function(i, el)
42
        {
43
            var el = allFrames[i];
44
45
            el.addEventListener(evento, (e) =>
46
            {
47
                e.preventDefault();
48
49
                allFrames[0].classList.remove("active");
50
                allFramesCode[0].classList.remove("active");
51
                
52
                if (previousFrame)
53
                {
54
                    previousFrame.classList.remove("active");                    
55
                }
56
                
57
                el.classList.add("active");  
58
                      
59
                previousFrame = el;
60
                                
61
                selectFrameInfo(el.attributes["data-index"].value);
62
            });
63
64
        })(i);
65
    }
66
67
})(document);