| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| 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 | /* |
||
| 16 | define(function() { |
||
| 17 | return { |
||
| 18 | |||
| 19 | defaults: { |
||
| 20 | options: { |
||
| 21 | selected: null, |
||
| 22 | locale: null, |
||
| 23 | selectCallback: function(item) { |
||
|
|
|||
| 24 | }, |
||
| 25 | cancelCallback: function() { |
||
| 26 | } |
||
| 27 | }, |
||
| 28 | translations: { |
||
| 29 | overlayTitle: 'public.choose' |
||
| 30 | } |
||
| 31 | }, |
||
| 32 | |||
| 33 | initialize: function() { |
||
| 34 | var $container = $('<div/>'); |
||
| 35 | var $componentContainer = $('<div/>'); |
||
| 36 | this.$el.append($container); |
||
| 37 | |||
| 38 | this.sandbox.start([ |
||
| 39 | { |
||
| 40 | name: 'overlay@husky', |
||
| 41 | options: { |
||
| 42 | el: $container, |
||
| 43 | openOnStart: true, |
||
| 44 | removeOnClose: true, |
||
| 45 | skin: 'medium', |
||
| 46 | slides: [ |
||
| 47 | { |
||
| 48 | title: this.translations.overlayTitle, |
||
| 49 | data: $componentContainer, |
||
| 50 | cssClass: 'data-source-slide', |
||
| 51 | contentSpacing: false, |
||
| 52 | okCallback: function() { |
||
| 53 | if (this.item) { |
||
| 54 | this.options.selectCallback(this.item); |
||
| 55 | } |
||
| 56 | }.bind(this), |
||
| 57 | cancelCallback: function() { |
||
| 58 | this.options.cancelCallback(); |
||
| 59 | }.bind(this) |
||
| 60 | } |
||
| 61 | ] |
||
| 62 | } |
||
| 63 | } |
||
| 64 | ]).then(this.startContentDatasource.bind(this, $componentContainer)); |
||
| 65 | }, |
||
| 66 | |||
| 67 | startContentDatasource: function($componentContainer) { |
||
| 68 | this.sandbox.start( |
||
| 69 | [ |
||
| 70 | { |
||
| 71 | name: 'content-datasource@sulucontent', |
||
| 72 | options: { |
||
| 73 | el: $componentContainer, |
||
| 74 | selected: this.options.selected, |
||
| 75 | locale: this.options.locale, |
||
| 76 | selectedUrl: '/admin/api/nodes/{datasource}?tree=true&language={locale}&fields=title,order,published&webspace-nodes=all', |
||
| 77 | rootUrl: '/admin/api/nodes?language={locale}&fields=title,order,published&webspace-nodes=all', |
||
| 78 | resultKey: 'nodes', |
||
| 79 | instanceName: 'internal-link', |
||
| 80 | instanceNamePrefix: '', |
||
| 81 | showStatus: true, |
||
| 82 | selectCallback: function(id, path, title, item) { |
||
| 83 | this.item = item; |
||
| 84 | }.bind(this) |
||
| 85 | } |
||
| 86 | } |
||
| 87 | ] |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | }; |
||
| 91 | }); |
||
| 92 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.