| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 | this.id = this.options.selected; |
||
| 35 | |||
| 36 | var $container = $('<div/>'); |
||
| 37 | var $componentContainer = $('<div/>'); |
||
| 38 | this.$el.append($container); |
||
| 39 | |||
| 40 | this.sandbox.start([ |
||
| 41 | { |
||
| 42 | name: 'overlay@husky', |
||
| 43 | options: { |
||
| 44 | el: $container, |
||
| 45 | openOnStart: true, |
||
| 46 | removeOnClose: true, |
||
| 47 | skin: 'medium', |
||
| 48 | instanceName: 'page-select', |
||
| 49 | slides: [ |
||
| 50 | { |
||
| 51 | title: this.translations.overlayTitle, |
||
| 52 | data: $componentContainer, |
||
| 53 | cssClass: 'data-source-slide', |
||
| 54 | contentSpacing: false, |
||
| 55 | okCallback: function() { |
||
| 56 | if (this.item) { |
||
| 57 | this.options.selectCallback(this.item); |
||
| 58 | } |
||
| 59 | }.bind(this), |
||
| 60 | cancelCallback: function() { |
||
| 61 | this.options.cancelCallback(); |
||
| 62 | }.bind(this) |
||
| 63 | } |
||
| 64 | ] |
||
| 65 | } |
||
| 66 | } |
||
| 67 | ]).then(this.startContentDatasource.bind(this, $componentContainer)); |
||
| 68 | }, |
||
| 69 | |||
| 70 | startContentDatasource: function($componentContainer) { |
||
| 71 | this.sandbox.start( |
||
| 72 | [ |
||
| 73 | { |
||
| 74 | name: 'content-datasource@sulucontent', |
||
| 75 | options: { |
||
| 76 | el: $componentContainer, |
||
| 77 | singleMarkable: true, |
||
| 78 | selected: this.options.selected, |
||
| 79 | locale: this.options.locale, |
||
| 80 | selectedUrl: '/admin/api/nodes/{datasource}?tree=true&language={locale}&fields=title,order,published,url&webspace-nodes=all', |
||
| 81 | rootUrl: '/admin/api/nodes?language={locale}&fields=title,order,published&webspace-nodes=all', |
||
| 82 | resultKey: 'nodes', |
||
| 83 | instanceName: 'internal-link', |
||
| 84 | instanceNamePrefix: '', |
||
| 85 | showStatus: true, |
||
| 86 | selectCallback: function(id, path, title, item) { |
||
| 87 | if (this.id === id) { |
||
| 88 | return this.setItem(null, null); |
||
| 89 | } |
||
| 90 | |||
| 91 | this.setItem(item, id); |
||
| 92 | }.bind(this) |
||
| 93 | } |
||
| 94 | } |
||
| 95 | ] |
||
| 96 | ); |
||
| 97 | }, |
||
| 98 | |||
| 99 | setItem: function(item, id) { |
||
| 100 | this.item = item; |
||
| 101 | this.id = id; |
||
| 102 | |||
| 103 | var action = 'activate'; |
||
| 104 | if (!item) { |
||
| 105 | action = 'deactivate'; |
||
| 106 | } |
||
| 107 | |||
| 108 | this.sandbox.emit('husky.overlay.page-select.okbutton.' + action); |
||
| 109 | } |
||
| 110 | }; |
||
| 111 | }); |
||
| 112 |
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.