Completed
Pull Request — master (#9)
by Flo
02:37
created

docs/assets/js/namespace.js   A

Complexity

Total Complexity 5
Complexity/F 5

Size

Lines of Code 30
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
dl 0
loc 30
cc 1
nc 2
mnd 2
bc 5
fnc 1
rs 10
bpm 5
cpm 5
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
B faulancer.namespace 0 26 4
1
/**
2
 * Define namespaces in javascript
3
 *
4
 * Usage:
5
 * _________________________________________________________________
6
 *|
7
 *| (function(dependency1, dependency2) {
8
 *|
9
 *|   'use strict';
10
 *|
11
 *|   // The namespace
12
 *|   var ns = faulancer.app.myscript;
13
 *|
14
 *|   // Private scope
15
 *|   var _private = {
16
 *|
17
 *|     doPrivateThings: function() {
18
 *|       this won't get exposed in public scope...
19
 *|     }
20
 *|
21
 *|   };
22
 *|
23
 *|   // Helper methods
24
 *|   var _helper = {
25
 *|     define helper methods...
26
 *|   };
27
 *|
28
 *|   // Private fields/attributes (with example values)
29
 *|   var _fields = {
30
 *|     fromTop:    0,
31
 *|     fromLeft:   0
32
 *|   };
33
 *|
34
 *|   // Public scope
35
 *|   ns = {
36
 *|
37
 *|     init: function() {
38
 *|       do initialization...
39
 *|     },
40
 *|
41
 *|     doThis: function() {
42
 *|       do this...
43
 *|     },
44
 *|
45
 *|     doThat: function() {
46
 *|       and that...
47
 *|     }
48
 *|
49
 *|   };
50
 *|
51
 *|   window.addEventListener('load', faulancer.app.myscript.init);
52
 *|
53
 *| }(faulancer.app.dependency1, faulancer.app.dependency2);
54
 *|_________________________________________________________________
55
 *
56
 */
57
58
if (typeof faulancer === 'undefined') {
0 ignored issues
show
Bug introduced by
The variable faulancer seems to be never declared. If this is a global, consider adding a /** global: faulancer */ 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...
59
    faulancer = {};
0 ignored issues
show
Bug introduced by
The variable faulancer seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.faulancer.
Loading history...
60
}
61
62
faulancer.namespace = function(namespace)
0 ignored issues
show
Bug introduced by
The variable faulancer does not seem to be initialized in case typeof faulancer === "undefined" on line 58 is false. Are you sure this can never be the case?
Loading history...
63
{
64
    'use strict';
65
66
    var parts = namespace.split('.'),
67
        parent = faulancer,
0 ignored issues
show
Bug introduced by
The variable faulancer does not seem to be initialized in case typeof faulancer === "undefined" on line 58 is false. Are you sure this can never be the case?
Loading history...
68
        i;
69
70
    // strip redundant leading global
71
    if (parts[0] === "faulancer") {
72
        parts = parts.slice(1);
73
    }
74
75
    for (i = 0; i < parts.length; i += 1) {
76
77
        // create a property if it doesn't exist
78
        if (typeof parent[parts[i]] === "undefined") {
79
            parent[parts[i]] = {};
80
        }
81
82
        parent = parent[parts[i]];
83
84
    }
85
86
    return parent;
87
};
88