| Conditions | 1 |
| Paths | 2 |
| Total Lines | 116 |
| 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 | data: { |
||
| 17 | contact: null |
||
| 18 | }, |
||
| 19 | selectCallback: function(data) { |
||
|
|
|||
| 20 | }, |
||
| 21 | matchings: [ |
||
| 22 | {'name': 'name', 'content': 'Name'}, |
||
| 23 | {'name': 'id', 'disabled': true}, |
||
| 24 | {'name': 'children', 'disabled': true}, |
||
| 25 | {'name': 'parent', 'disabled': true} |
||
| 26 | ] |
||
| 27 | }, |
||
| 28 | translations: { |
||
| 29 | title: 'sulu_article.category-selection-overlay.title' |
||
| 30 | }, |
||
| 31 | templates: { |
||
| 32 | skeleton: [ |
||
| 33 | '<div class="grid">', |
||
| 34 | ' <div class="grid-row">', |
||
| 35 | ' <div class="grid-col-12 category-selection-list"/>', |
||
| 36 | ' </div>', |
||
| 37 | '</div>' |
||
| 38 | ].join('') |
||
| 39 | } |
||
| 40 | }; |
||
| 41 | |||
| 42 | return { |
||
| 43 | |||
| 44 | defaults: defaults, |
||
| 45 | |||
| 46 | initialize: function() { |
||
| 47 | var $overlayContainer = $('<div/>'); |
||
| 48 | this.$el.append($overlayContainer); |
||
| 49 | |||
| 50 | this.data = this.options.data; |
||
| 51 | |||
| 52 | // start overlay |
||
| 53 | this.sandbox.start([{ |
||
| 54 | name: 'overlay@husky', |
||
| 55 | options: { |
||
| 56 | el: $overlayContainer, |
||
| 57 | instanceName: 'category-selection', |
||
| 58 | openOnStart: true, |
||
| 59 | removeOnClose: true, |
||
| 60 | skin: 'medium', |
||
| 61 | slides: [ |
||
| 62 | { |
||
| 63 | title: this.translations.title, |
||
| 64 | data: $(this.templates.skeleton({ |
||
| 65 | translations: this.translations |
||
| 66 | })), |
||
| 67 | okCallback: this.okCallbackOverlay.bind(this) |
||
| 68 | } |
||
| 69 | ] |
||
| 70 | } |
||
| 71 | }]); |
||
| 72 | |||
| 73 | this.sandbox.once('husky.overlay.category-selection.opened', function() { |
||
| 74 | this.sandbox.start([ |
||
| 75 | { |
||
| 76 | name: 'datagrid@husky', |
||
| 77 | options: { |
||
| 78 | el: $overlayContainer.find('.category-selection-list'), |
||
| 79 | instanceName: 'category-selection', |
||
| 80 | url: '/admin/api/categories?locale=' + this.options.locale + '&flat=true&sortBy=name&sortOrder=asc', |
||
| 81 | resultKey: 'categories', |
||
| 82 | sortable: false, |
||
| 83 | selectedCounter: false, |
||
| 84 | preselected: !!this.options.data.category ? [this.options.data.category.id] : [], |
||
| 85 | paginationOptions: { |
||
| 86 | dropdown: { |
||
| 87 | limit: 20 |
||
| 88 | } |
||
| 89 | }, |
||
| 90 | childrenPropertyName: 'hasChildren', |
||
| 91 | viewOptions: { |
||
| 92 | table: { |
||
| 93 | cropContents: false, |
||
| 94 | noItemsText: 'sulu.category.no-categories-available', |
||
| 95 | showHead: false, |
||
| 96 | cssClass: 'white-box', |
||
| 97 | selectItem: { |
||
| 98 | type: 'radio', |
||
| 99 | inFirstCell: true |
||
| 100 | } |
||
| 101 | } |
||
| 102 | }, |
||
| 103 | matchings: this.options.matchings |
||
| 104 | } |
||
| 105 | } |
||
| 106 | ]); |
||
| 107 | }.bind(this)); |
||
| 108 | }, |
||
| 109 | |||
| 110 | /** |
||
| 111 | * OK callback of the overlay. |
||
| 112 | */ |
||
| 113 | okCallbackOverlay: function() { |
||
| 114 | this.sandbox.emit('husky.datagrid.category-selection.items.get-selected', function(ids, items) { |
||
| 115 | if (items.length > 0) { |
||
| 116 | this.data.categoryId = ids[0]; |
||
| 117 | this.data.categoryItem = items[0]; |
||
| 118 | } |
||
| 119 | |||
| 120 | this.options.selectCallback(this.data); |
||
| 121 | this.sandbox.stop(); |
||
| 122 | }.bind(this), true); |
||
| 123 | } |
||
| 124 | }; |
||
| 125 | }); |
||
| 126 |
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.