| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 | /* |
||
| 10 | define(['jquery'], function($) { |
||
| 11 | |||
| 12 | 'use strict'; |
||
| 13 | |||
| 14 | var defaults = { |
||
| 15 | options: { |
||
| 16 | locale: null, |
||
| 17 | data: { |
||
| 18 | category: null |
||
| 19 | }, |
||
| 20 | selectCallback: function(data) { |
||
|
|
|||
| 21 | } |
||
| 22 | }, |
||
| 23 | translations: { |
||
| 24 | title: 'sulu_article.category-selection-overlay.title' |
||
| 25 | } |
||
| 26 | }; |
||
| 27 | |||
| 28 | return { |
||
| 29 | |||
| 30 | defaults: defaults, |
||
| 31 | |||
| 32 | initialize: function() { |
||
| 33 | var $overlayContainer = $('<div/>'); |
||
| 34 | var $componentContainer = $('<div/>'); |
||
| 35 | this.$el.append($overlayContainer); |
||
| 36 | |||
| 37 | this.data = this.options.data; |
||
| 38 | |||
| 39 | // start overlay |
||
| 40 | this.sandbox.start([{ |
||
| 41 | name: 'overlay@husky', |
||
| 42 | options: { |
||
| 43 | el: $overlayContainer, |
||
| 44 | instanceName: 'category-selection', |
||
| 45 | openOnStart: true, |
||
| 46 | removeOnClose: true, |
||
| 47 | skin: 'medium', |
||
| 48 | slides: [ |
||
| 49 | { |
||
| 50 | title: this.translations.title, |
||
| 51 | data: $componentContainer, |
||
| 52 | okCallback: this.okCallbackOverlay.bind(this) |
||
| 53 | } |
||
| 54 | ] |
||
| 55 | } |
||
| 56 | }]); |
||
| 57 | |||
| 58 | this.sandbox.once('husky.overlay.category-selection.opened', function() { |
||
| 59 | this.sandbox.start([{ |
||
| 60 | name: 'articles/list/category-selection/form@suluarticle', |
||
| 61 | options: { |
||
| 62 | el: $componentContainer, |
||
| 63 | locale: this.options.locale, |
||
| 64 | data: this.options.data, |
||
| 65 | selectCallback: function(data) { |
||
| 66 | this.options.selectCallback(data); |
||
| 67 | this.sandbox.stop(); |
||
| 68 | }.bind(this) |
||
| 69 | } |
||
| 70 | }]); |
||
| 71 | }.bind(this)); |
||
| 72 | }, |
||
| 73 | |||
| 74 | /** |
||
| 75 | * OK callback of the overlay. |
||
| 76 | */ |
||
| 77 | okCallbackOverlay: function() { |
||
| 78 | this.sandbox.emit('sulu_article.category-selection.form.get'); |
||
| 79 | } |
||
| 80 | }; |
||
| 81 | }); |
||
| 82 |
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.