| Conditions | 1 |
| Paths | 2 |
| Total Lines | 95 |
| 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 | define([ |
||
| 9 | ], function ( |
||
| 10 | declare, |
||
| 11 | _TemplatedMixin, |
||
| 12 | _WidgetsInTemplateMixin, |
||
| 13 | Dialog, |
||
| 14 | topic, |
||
| 15 | template, |
||
| 16 | DomUtils |
||
|
|
|||
| 17 | ) { |
||
| 18 | return declare([Dialog, _TemplatedMixin, _WidgetsInTemplateMixin], { |
||
| 19 | |||
| 20 | templateString: template, |
||
| 21 | parentNode: null, |
||
| 22 | baseClass: 'language-dialog', |
||
| 23 | title: 'Edit language', |
||
| 24 | language: null, |
||
| 25 | edit: true, |
||
| 26 | |||
| 27 | postCreate: function () { |
||
| 28 | this.inherited(arguments); |
||
| 29 | }, |
||
| 30 | |||
| 31 | startup: function () { |
||
| 32 | this.inherited(arguments); |
||
| 33 | |||
| 34 | }, |
||
| 35 | |||
| 36 | setData: function(language) { |
||
| 37 | console.log(language); |
||
| 38 | this.codeInputNode.value = language.id; |
||
| 39 | this.descriptionInputNode.value = language.name; |
||
| 40 | }, |
||
| 41 | |||
| 42 | hide: function () { |
||
| 43 | this.inherited(arguments); |
||
| 44 | this.reset(); |
||
| 45 | }, |
||
| 46 | |||
| 47 | show: function (language) { |
||
| 48 | this.inherited(arguments); |
||
| 49 | this.reset(); |
||
| 50 | if (language) { |
||
| 51 | this.setData(language); |
||
| 52 | this.set('title', 'Edit language'); |
||
| 53 | this.okButtonNode.innerHTML = 'Edit'; |
||
| 54 | this.edit = true; |
||
| 55 | this.language = language; |
||
| 56 | } else { |
||
| 57 | this.set('title', 'Add new language'); |
||
| 58 | this.okButtonNode.innerHTML = 'Add'; |
||
| 59 | this.edit = false; |
||
| 60 | } |
||
| 61 | }, |
||
| 62 | |||
| 63 | _okClick: function (evt) { |
||
| 64 | console.debug('languageDialog::_okClick'); |
||
| 65 | evt.preventDefault(); |
||
| 66 | if (this._validate()) { |
||
| 67 | this.language.id = this.codeInputNode.value; |
||
| 68 | this.language.name = this.descriptionInputNode.value; |
||
| 69 | if (this.edit) { |
||
| 70 | this.emit('edit.language', { |
||
| 71 | language: this.language, |
||
| 72 | }); |
||
| 73 | } else { |
||
| 74 | this.emit('add.language', { |
||
| 75 | language: this.language |
||
| 76 | }); |
||
| 77 | } |
||
| 78 | this.hide(); |
||
| 79 | } else { |
||
| 80 | topic.publish('dGrowl', 'Please fill in at least a language code.', { |
||
| 81 | 'title': 'Invalid language', |
||
| 82 | 'sticky': false, |
||
| 83 | 'channel': 'info' |
||
| 84 | }); |
||
| 85 | } |
||
| 86 | }, |
||
| 87 | |||
| 88 | _cancelClick: function (evt) { |
||
| 89 | console.debug('languageDialog::_cancelClick'); |
||
| 90 | evt.preventDefault(); |
||
| 91 | this.hide(); |
||
| 92 | }, |
||
| 93 | |||
| 94 | reset: function () { |
||
| 95 | this.codeInputNode.value = ''; |
||
| 96 | this.descriptionInputNode.value = ''; |
||
| 97 | }, |
||
| 98 | |||
| 99 | _validate: function () { |
||
| 100 | return (this.codeInputNode.value.trim() !== null && this.codeInputNode.value.trim() !== ''); |
||
| 101 | } |
||
| 102 | }); |
||
| 103 | }); |
||
| 104 |
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.