Passed
Push — master ( bd974e...3dc51d )
by Kolja
01:04
created

guard.js   A

Complexity

Total Complexity 9
Complexity/F 2.25

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 16
c 1
b 0
f 0
nc 1
dl 0
loc 35
rs 10
wmc 9
mnd 1
bc 8
fnc 4
bpm 2
cpm 2.25
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A ➔ assertValidMetadata 0 5 2
A ➔ assertNonEmptyStringParameter 0 5 2
A ➔ assertValidMetadataOrNull 0 5 2
A ➔ assertValidDirected 0 5 2
1
const check = require('check-types');
2
3
/**
4
 * Various guards.
5
 */
6
class Guard {
7
8
    static assertNonEmptyStringParameter(name, value) {
9
        if (!check.nonEmptyString(value)) {
10
            throw new Error('Parameter "' + name + '" has to be an non-empty string.');
11
        }
12
    }
13
14
    static assertValidMetadata(metadata) {
15
        if (!check.nonEmptyObject(metadata)) {
16
            throw new Error('Metadata on an node has to be an object.');
17
        }
18
    }
19
20
    static assertValidMetadataOrNull(metadataOrNull) {
21
        if (check.assigned(metadataOrNull)) {
22
            Guard.assertValidMetadata(metadataOrNull);
23
        }
24
    }
25
26
    static assertValidDirected(directed) {
27
        if (!check.boolean(directed)) {
28
            throw new Error('Directed flag on an edge has to be boolean.');
29
        }
30
    }
31
}
32
33
module.exports = {
34
    Guard,
35
};