Conditions | 1 |
Paths | 2 |
Total Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
1 | /** |
||
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){ |
||
|
|||
76 | return this.links.getLink(rel); |
||
77 | } |
||
78 | }; |
||
79 | |||
80 | }; |
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
The function
isBig
will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly returnundefined
.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.