lib/API/Barricade.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 39
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A Barricade.js ➔ Barricade 0 19 1
1
var Schema = require('../Schema')
2
var Normalizer = Schema.Normalizer
3
var Validator = Schema.Validator
4
var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j
5
var Printer = require('./Printer').Printer
6
var InvalidInputError = require('../Error').InvalidInputError
7
8
/**
9
 * This class provide so-called barricade functionality - it validates
10
 * and converts user input and, if input is invalid, prevents following
11
 * actions by raising an exception.
12
 *
13
 * @param {TBarricadeOptions} [options]
14
 *
15
 * @class
16
 */
17
function Barricade (options) {
18
  options = options || {}
19
  var logger = Slf4j.factory(options.logger, 'ama-team.vsf.barricade')
20
  var printer = options.printer || new Printer(options.logger)
21
22
  /**
23
   * @param {TScenarioInput} input
24
   * @return {TScenario}
25
   */
26
  this.scenario = function (input) {
27
    var violations = Validator.scenario(input)
28
    logger.info('Running scenario validation')
29
    printer.violations(violations)
30
    if (violations.severity === Validator.Severity.Fatal) {
31
      throw new InvalidInputError('Scenario validation has failed')
32
    }
33
    return Normalizer.scenario(input)
34
  }
35
}
36
37
module.exports = {
38
  Barricade: Barricade
39
}
40