Passed
Branch master (27f176)
by refat
18:17
created

resources/js/classes/validation/Characters.js   A

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 42
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 8
mnd 1
bc 1
fnc 7
bpm 0.1428
cpm 1.1428
noi 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A Characters.canCharsSeparateViaComma 0 3 1
A Characters.formatCharsViaComma 0 8 2
A Characters.constructor 0 11 1
A Characters.formatCharsString 0 3 1
A Characters.isCharsString 0 3 1
A Characters.isCharsAnArray 0 3 1
A Characters.isObject 0 3 1
1
export default class Characters {
2
  constructor(value, object = {}) {
3
    this.object = object;
4
    this.chars = '';
5
    this.times = 0;
6
    this.atFirst = null;
7
    this.atEnd = null;
8
    this.between = null;
9
    this.langsRegex = '';
10
    this.languages = '';
11
    this.value = value || null;
12
  }
13
14
  isObject() {
15
    return (typeof this.object === 'object' && Object.keys(this.object).length);
16
  }
17
18
  isCharsString() {
19
    return (typeof this.chars === 'string');
20
  }
21
22
  isCharsAnArray() {
23
    return Array.isArray(this.chars);
24
  }
25
26
  canCharsSeparateViaComma() {
27
    return this.char.match(/,/) && this.char.match(/,/g).length > 1;
28
  }
29
30
  formatCharsViaComma($comma) {
31
    if ($comma) {
32
      this.chars = this.chars.split(',');
33
    } else {
34
      this.chars = this.chars.split('');
35
    }
36
    return `\\${this.chars.join('\\')}`;
37
  }
38
39
  formatCharsString() {
40
    return this.formatCharsViaComma(this.canCharsSeparateViaComma());
41
  }
42
}
43