| Conditions | 1 |
| Paths | 2 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
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 | /* |
||
| 29 | (function () { |
||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * @constructs Circles |
||
| 34 | */ |
||
| 35 | var Circles = function () { |
||
| 36 | |||
| 37 | $.extend(Circles.prototype, circles); |
||
|
|
|||
| 38 | $.extend(Circles.prototype, members); |
||
| 39 | $.extend(Circles.prototype, links); |
||
| 40 | |||
| 41 | this.initialize(); |
||
| 42 | }; |
||
| 43 | |||
| 44 | Circles.prototype = { |
||
| 45 | |||
| 46 | |||
| 47 | initialize: function () { |
||
| 48 | |||
| 49 | var self = this; |
||
| 50 | |||
| 51 | |||
| 52 | this.shareToCircle = function (circleId, source, type, item, callback) { |
||
| 53 | var result = {status: -1}; |
||
| 54 | $.ajax({ |
||
| 55 | method: 'PUT', |
||
| 56 | url: OC.generateUrl('/apps/circles/v1/circles/' + circleId + '/share'), |
||
| 57 | data: { |
||
| 58 | source: source, |
||
| 59 | type: type, |
||
| 60 | item: item |
||
| 61 | } |
||
| 62 | }).done(function (res) { |
||
| 63 | self.onCallback(callback, res); |
||
| 64 | }).fail(function () { |
||
| 65 | self.onCallback(callback, result); |
||
| 66 | }); |
||
| 67 | }; |
||
| 68 | |||
| 69 | this.onCallback = function (callback, result) { |
||
| 70 | if (callback && (typeof callback === 'function')) { |
||
| 71 | if (typeof result === 'object') { |
||
| 72 | callback(result); |
||
| 73 | } else { |
||
| 74 | callback({status: -1}); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | }; |
||
| 78 | |||
| 79 | } |
||
| 80 | |||
| 81 | }; |
||
| 82 | |||
| 83 | OCA.Circles = Circles; |
||
| 84 | OCA.Circles.api = new Circles(); |
||
| 85 | |||
| 86 | })(); |
||
| 87 | |||
| 89 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.