Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

Identifiers.js ➔ Identifiers   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
c 1
b 0
f 1
nc 5
nop 1
dl 0
loc 22
rs 8.6737
1
var utils = require('./utils');
2
3
/**
4
 * Manage the set of identifers for an object.
5
 * 
6
 * @constructor
7
 * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
8
 */
9
var Identifiers = function(json){
10
  
11
  // Protect against forgetting the new keyword when calling the constructor
12
  if(!(this instanceof Identifiers)){
13
    return new Identifiers(json);
14
  }
15
  
16
  // If the given object is already an instance then just return it. DON'T copy it.
17
  if(Identifiers.isInstance(json)){
18
    return json;
19
  }
20
  
21
  this.identifiers = {};
22
  
23
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
24
    if(json instanceof Identifiers){
25
      this.identifiers = json.identifiers;
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...
26
    } else {
27
      this.identifiers = 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...
28
    }
29
  }
30
};
31
32
Identifiers._gedxClass = Identifiers.prototype._gedxClass = 'GedcomX.Identifiers';
33
34
/**
35
 * Check whether the given object is an instance of this class.
36
 * 
37
 * @param {Object} obj
38
 * @returns {Boolean}
39
 */
40
Identifiers.isInstance = function(obj){
41
  return utils.isInstance(obj, this._gedxClass);
42
};
43
44
45
/**
46
 * Export the object as JSON
47
 * 
48
 * @return {Object} JSON object
49
 */
50
Identifiers.prototype.toJSON = function(){
51
  return this.identifiers;
52
};
53
54
module.exports = Identifiers;