src/core/ExtensibleData.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 87
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

6 Functions

Rating   Name   Duplication   Size   Complexity  
A ExtensibleData.getId 0 3 1
A ExtensibleData.init 0 9 2
A ExtensibleData.setId 0 4 1
A ExtensibleData.isInstance 0 3 1
A ExtensibleData.toJSON 0 3 1
A ExtensibleData.js ➔ ExtensibleData 0 14 3
1
var utils = require('../utils'),
2
    Base = require('../Base');
3
4
/**
5
 * A set of data that supports extension elements.
6
 * 
7
 * @class
8
 * @extends Base
9
 * @param {Object} [json]
10
 */
11
var ExtensibleData = function(json){
12
  
13
  // Protect against forgetting the new keyword when calling the constructor
14
  if(!(this instanceof ExtensibleData)){
15
    return new ExtensibleData(json);
16
  }
17
  
18
  // If the given object is already an instance then just return it. DON'T copy it.
19
  if(ExtensibleData.isInstance(json)){
20
    return json;
21
  }
22
  
23
  this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
24
};
25
26
ExtensibleData.prototype = Object.create(Base.prototype);
27
28
ExtensibleData._gedxClass = ExtensibleData.prototype._gedxClass = 'GedcomX.ExtensibleData';
29
30
ExtensibleData.jsonProps = ['id'];
31
32
/**
33
 * Check whether the given object is an instance of this class.
34
 * 
35
 * @param {Object} obj
36
 * @returns {Boolean}
37
 */
38
ExtensibleData.isInstance = function(obj){
39
  return utils.isInstance(obj, this._gedxClass);
40
};
41
42
/**
43
 * Initialize from JSON
44
 * 
45
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
46
 * @return {ExtensibleData} this
47
 */
48
ExtensibleData.prototype.init = function(json){
49
  
50
  Base.prototype.init.call(this, json);
51
  
52
  if(json){
53
    this.setId(json.id);
54
  }
55
  return this;
56
};
57
58
/**
59
 * Get the object's id.
60
 * 
61
 * @returns {String} Id 
62
 */
63
ExtensibleData.prototype.getId = function(){
64
  return this.id;
65
};
66
67
/**
68
 * Set the object's id.
69
 * 
70
 * @param {String} id
71
 * @return {ExtensibleData} This object, for chaining.
72
 */
73
ExtensibleData.prototype.setId = function(id){
74
  this.id = id;
75
  return this;
76
};
77
78
/**
79
 * Export the object as JSON
80
 * 
81
 * @return {Object} JSON object
82
 */
83
ExtensibleData.prototype.toJSON = function(){
84
  return this._toJSON(Base, ExtensibleData.jsonProps);
85
};
86
87
module.exports = ExtensibleData;