Completed
Push — master ( e3ee1d...5cbb1b )
by Justin
01:36
created

module.exports   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 135

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 135
rs 8.2857

10 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 11 2
A 0 3 1
A 0 4 1
A 0 3 1
A 0 3 1
A 0 4 1
A 0 3 1
A 0 4 1
A 0 3 1
A 0 14 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
module.exports = function(GedcomX){
2
  
3
  var utils = require('../utils');
4
  
5
  /**
6
   * Information about the contents of a collection.
7
   * 
8
   * @constructor
9
   * @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...
10
   */
11
  var CollectionContent = function(json){
12
    
13
    // Protect against forgetting the new keyword when calling the constructor
14
    if(!(this instanceof CollectionContent)){
15
      return new CollectionContent(json);
16
    }
17
    
18
    // If the given object is already an instance then just return it. DON'T copy it.
19
    if(CollectionContent.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
  CollectionContent.prototype = Object.create(GedcomX.ExtensibleData.prototype);
27
  
28
  CollectionContent._gedxClass = CollectionContent.prototype._gedxClass = 'GedcomX.CollectionContent';
29
  
30
  CollectionContent.jsonProps = [
31
    'resourceType',
32
    'count',
33
    'completeness'
34
  ];
35
  
36
  /**
37
   * Check whether the given object is an instance of this class.
38
   * 
39
   * @param {Object} obj
40
   * @returns {Boolean}
41
   */
42
  CollectionContent.isInstance = function(obj){
43
    return utils.isInstance(obj, this._gedxClass);
44
  };
45
46
  /**
47
   * Initialize from JSON
48
   * 
49
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
50
   * @return {CollectionContent} this
51
   */
52
  CollectionContent.prototype.init = function(json){
53
    
54
    GedcomX.ExtensibleData.prototype.init.call(this, json);
55
    
56
    if(json){
57
      this.setResourceType(json.resourceType);
58
      this.setCount(json.count);
59
      this.setCompleteness(json.completeness);
60
    }
61
    return this;
62
  };
63
  
64
  /**
65
   * Set the resource type
66
   * 
67
   * @param {String} resourceType
68
   * @return {CollectionContent} this
69
   */
70
  CollectionContent.prototype.setResourceType = function(resourceType){
71
    this.resourceType = resourceType;
72
    return this;
73
  };
74
  
75
  /**
76
   * Get the resource type
77
   * 
78
   * @return {String} resourceType
79
   */
80
  CollectionContent.prototype.getResourceType = function(){
81
    return this.resourceType;
82
  };
83
  
84
  /**
85
   * Set the count
86
   * 
87
   * @param {Integer} count
88
   * @return {CollectionContent} this
89
   */
90
  CollectionContent.prototype.setCount = function(count){
91
    this.count = count;
92
    return this;
93
  };
94
  
95
  /**
96
   * Get the count
97
   * 
98
   * @return {Integer}
99
   */
100
  CollectionContent.prototype.getCount = function(){
101
    return this.count;
102
  };
103
  
104
  /**
105
   * Set the completeness
106
   * 
107
   * @param {Number} completeness A number between 0 and 1
108
   * @return {CollectionContent}
109
   */
110
  CollectionContent.prototype.setCompleteness = function(completeness){
111
    this.completeness = completeness;
112
    return this;
113
  };
114
  
115
  /**
116
   * Get the completeness
117
   * 
118
   * @return {Number} completeness
119
   */
120
  CollectionContent.prototype.getCompleteness = function(){
121
    return this.completeness;
122
  };
123
   
124
  /**
125
   * Export the object as JSON
126
   * 
127
   * @return {Object} JSON object
128
   */
129
  CollectionContent.prototype.toJSON = function(){
130
    return this._toJSON(GedcomX.ExtensibleData, CollectionContent.jsonProps);
131
  };
132
  
133
  GedcomX.CollectionContent = CollectionContent;
134
  
135
};