GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 86eabc...c09291 )
by Steeven
08:41
created

src/Views/assets/js/print-out.js   A

Complexity

Total Complexity 12
Complexity/F 2.4

Size

Lines of Code 50
Function Count 5

Duplication

Duplicated Lines 12
Ratio 24 %

Importance

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

4 Functions

Rating   Name   Duplication   Size   Complexity  
A print-out.js ➔ gearCopySelectionText 0 9 2
A print-out.js ➔ gearSelectCode 0 11 3
A print-out.js ➔ gearGetSelectionText 0 7 5
A print-out.js ➔ gearCopyCode 0 7 2

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
/*
2
 * This file is part of the O2System Framework package.
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @author         Steeve Andrian Salim
8
 * @copyright      Copyright (c) Steeve Andrian Salim
9
 */
10
// ------------------------------------------------------------------------
11 View Code Duplication
(function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
    var pre = document.getElementsByTagName('pre'),
13
        preLen = pre.length;
14
    for (var i = 0; i < preLen; i++) {
15
        pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="clear-both"></span>';
16
        var linesNum = pre[i].innerHTML.split(/\n/).length;
17
        for (var number = 0; number < linesNum; number++) {
18
            var lineNumber = pre[i].getElementsByTagName('span')[0];
19
            lineNumber.innerHTML += '<span>' + (number + 1) + '</span>';
20
        }
21
    }
22
})();
23
24
function gearGetSelectionText() {
25
    var selectedText = ""
26
    if (window.getSelection) { // all modern browsers and IE9+
27
        selectedText = window.getSelection().toString()
28
    }
29
    return selectedText;
30
}
31
32
function gearCopySelectionText() {
33
    var isCopied // var to check whether execCommand successfully executed
34
    try {
35
        isCopied = document.execCommand("copy") // run command to copy selected text to clipboard
36
    } catch (e) {
37
        isCopied = false
38
    }
39
    return isCopied;
40
}
41
42
function gearSelectCode() {
43
    if (document.selection) {
44
        var range = document.body.createTextRange();
45
        range.moveToElementText(document.getElementById('gear-code-container'));
46
        range.select();
47
    } else if (window.getSelection) {
48
        var range = document.createRange();
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable range already seems to be declared on line 44. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
49
        range.selectNode(document.getElementById('gear-code-container'));
50
        window.getSelection().addRange(range);
51
    }
52
}
53
54
function gearCopyCode() {
55
    var selected = gearGetSelectionText() // call gearGetSelectionText() to see what was selected
56
    if (selected.length > 0) { // if selected text length is greater than 0
57
        var isCopied = gearCopySelectionText() // copy user selected text to clipboard
0 ignored issues
show
Unused Code introduced by
The variable isCopied seems to be never used. Consider removing it.
Loading history...
58
        alert('Copied to clipboard');
0 ignored issues
show
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
59
    }
60
}