Passed
Push — master ( b96352...904877 )
by Dominik
07:38 queued 02:47
created

assets/scripts/ExternalScriptLoader/index.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 33
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 7
mnd 2
bc 2
fnc 5
bpm 0.4
cpm 1.4
noi 1

4 Functions

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ importAll 0 5 2
A ExternalScriptLoader.initialize 0 6 2
A ExternalScriptLoader.getInstance 0 3 1
A ExternalScriptLoader.constructor 0 6 2
1
const providers = {}
2
3
// load all files from ./Providers folder into providers variable
4
function importAll (moduleRequire) {
5
  moduleRequire.keys().forEach(key => {
6
    providers[key.substr(2, key.length - 5)] = moduleRequire(key).init
7
  })
8
}
9
importAll(require.context('./Providers/', true, /\.js$/))
10
11
let instance
12
13
class ExternalScriptLoader {
14
  constructor () {
15
    if (!instance) {
16
      instance = this
17
    }
18
    return instance
0 ignored issues
show
Bug introduced by
The constructor does not have a meaningful return value. Are you sure this is correct?
Loading history...
19
  }
20
21
  static getInstance () {
22
    return instance || new ExternalScriptLoader()
23
  }
24
25
  initialize (type, options = {}) {
26
    if (!this[type]) {
27
      this[type] = providers[type](options)
28
    }
29
    return this[type]
30
  }
31
}
32
33
window.FlyntExternalScriptLoader = ExternalScriptLoader
34