Passed
Push — master ( 527212...0fe9bd )
by Pieter Epeüs
02:47 queued 52s
created

src/int.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 23
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
mnd 1
bc 1
fnc 2
dl 0
loc 23
rs 10
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0
ccs 4
cts 4
cp 1

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Int.constructor 0 4 1
A Int.validate 0 5 2
1
/**
2
 * An integer is a custom type based on the default number type.
3
 * It can only contain integers, and throw an error if it doesnt reveive it.
4
 */
5
export default class Int extends Number {
6
    /**
7
     * Constructor that receive the value,
8
     * and pass it to the number constructor.
9
     *
10
     * @param {number} value
11
     */
12
    constructor(value) {
13 4
        super(value);
14 4
        this.validate(value);
15
    }
16
17
    /**
18
     * Validate the value, it should throw an error if it isnt a integer.
19
     *
20
     * @param {number} value
21
     */
22
    validate(value) {
23 4
        if (parseInt(value, 10) !== value) {
24 1
            throw new Error(`${value} isnt an integer`);
25
        }
26
    }
27
}
28