Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

src/atom/AtomCommon.js   A

Complexity

Total Complexity 11
Complexity/F 1.38

Size

Lines of Code 110
Function Count 8

Duplication

Duplicated Lines 110
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 110
loc 110
rs 10
wmc 11
mnd 1
bc 11
fnc 8
bpm 1.375
cpm 1.375
noi 3

8 Functions

Rating   Name   Duplication   Size   Complexity  
A AtomCommon.getLang 3 3 1
A AtomCommon.init 10 10 2
A AtomCommon.isInstance 3 3 1
A AtomCommon.js ➔ AtomCommon 14 14 3
A AtomCommon.toJSON 3 3 1
A AtomCommon.setBase 4 4 1
A AtomCommon.getBase 3 3 1
A AtomCommon.setLang 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
var utils = require('../utils'),
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    Base = require('../Base');
3
4
/**
5
 * Common attributes for all Atom entities
6
 * 
7
 * @constructor
8
 * @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...
9
 */
10
var AtomCommon = function(json){
11
  
12
  // Protect against forgetting the new keyword when calling the constructor
13
  if(!(this instanceof AtomCommon)){
14
    return new AtomCommon(json);
15
  }
16
  
17
  // If the given object is already an instance then just return it. DON'T copy it.
18
  if(AtomCommon.isInstance(json)){
19
    return json;
20
  }
21
  
22
  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...
23
};
24
25
AtomCommon.prototype = Object.create(Base.prototype);
26
27
AtomCommon._gedxClass = AtomCommon.prototype._gedxClass = 'GedcomX.AtomCommon';
28
29
AtomCommon.jsonProps = [
30
  'base',
31
  'lang'
32
];
33
34
/**
35
 * Check whether the given object is an instance of this class.
36
 * 
37
 * @param {Object} obj
38
 * @returns {Boolean}
39
 */
40
AtomCommon.isInstance = function(obj){
41
  return utils.isInstance(obj, this._gedxClass);
42
};
43
44
/**
45
 * Initialize from JSON
46
 * 
47
 * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
48
 * @return {AtomCommon} this
49
 */
50
AtomCommon.prototype.init = function(json){
51
  
52
  Base.prototype.init.call(this, json);
53
  
54
  if(json){
55
    this.setBase(json.base);
56
    this.setLang(json.lang);
57
  }
58
  return this;
59
};
60
61
/**
62
 * Set the base attribute
63
 * 
64
 * @param {String} base
65
 * @return {AtomCommon} this
66
 */
67
AtomCommon.prototype.setBase = function(base){
68
  this.base = base;
69
  return this;
70
};
71
72
/**
73
 * Get the base
74
 * 
75
 * @return {String} base
76
 */
77
AtomCommon.prototype.getBase = function(base){
78
  return this.base;
79
};
80
81
/**
82
 * Set the lang
83
 * 
84
 * @param {String} lang
85
 * @return {AtomCommon} this
86
 */
87
AtomCommon.prototype.setLang = function(lang){
88
  this.lang = lang;
89
  return this;
90
};
91
92
/**
93
 * Get the lang
94
 * 
95
 * @return {String} lang
96
 */
97
AtomCommon.prototype.getLang = function(lang){
98
  return this.lang;
99
};
100
101
/**
102
 * Export the object as JSON
103
 * 
104
 * @return {Object} JSON object
105
 */
106
AtomCommon.prototype.toJSON = function(){
107
  return this._toJSON(Base, AtomCommon.jsonProps);
108
};
109
110
module.exports = AtomCommon;
111