Completed
Push — master ( eea0b2...e9f487 )
by Justin
01:29
created

module.exports   B

Complexity

Conditions 1
Paths 2

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 77
rs 8.9342

5 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 6 2
A 0 3 2
A 0 5 2
A 0 9 3
A 0 6 2

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
/**
2
 * RS extensions to ExtensibleData
3
 */
4
module.exports = function(GedcomX){
5
  
6
  // Extend serialization properties
7
  GedcomX.ExtensibleData.jsonProps.push('links');
8
  
9
  // Override init()
10
  var oldExtensibleDataInit = GedcomX.ExtensibleData.prototype.init;
11
  GedcomX.ExtensibleData.prototype.init = function(json){
12
    oldExtensibleDataInit.call(this, json);
13
    if(json){
14
      this.setLinks(json.links);
15
    }
16
  };
17
  
18
  /**
19
   * Set the links
20
   * 
21
   * @function setLinks
22
   * @instance
23
   * @memberof ExtensibleData
24
   * @param {Links} links
25
   * @return {ExtensibleData} this
26
   */
27
  GedcomX.ExtensibleData.prototype.setLinks = function(links){
28
    if(links){
29
      this.links = GedcomX.Links(links);
30
    }
31
    return this;
32
  };
33
  
34
  /**
35
   * Add a link
36
   * 
37
   * @function addLink
38
   * @instance
39
   * @memberof ExtensibleData
40
   * @param {Link} link
41
   * @return {ExtensibleData} this
42
   */
43
  GedcomX.ExtensibleData.prototype.addLink = function(link){
44
    if(link){
45
      if(!this.links){
46
        this.links = GedcomX.Links();
47
      }
48
      this.links.addLink(link);
49
    }
50
    return this;
51
  };
52
  
53
  /**
54
   * Get the links
55
   * 
56
   * @function getLinks
57
   * @instance
58
   * @memberof ExtensibleData
59
   * @return {Link[]}
60
   */
61
  GedcomX.ExtensibleData.prototype.getLinks = function(){
62
    return this.links ? this.links.getLinks() : [];
63
  };
64
  
65
  /**
66
   * Get a link
67
   * 
68
   * @function getLink
69
   * @instance
70
   * @memberof ExtensibleData
71
   * @param {String} rel
72
   * @return {Link}
73
   */
74
  GedcomX.ExtensibleData.prototype.getLink = function(rel){
75
    if(this.links){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.links 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...
76
      return this.links.getLink(rel);
77
    }
78
  };
79
  
80
};