Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 | /** |
||
41 | add: function ( e, data ) { |
||
42 | |||
43 | data.id = Date.now(); |
||
44 | |||
45 | var status = $('<li>') |
||
46 | .attr( 'id', data.id ) |
||
47 | .text( data.files[0].name ); |
||
48 | |||
49 | $( '#fileupload-results' ).append( status ); |
||
50 | |||
51 | var api = new mw.Api(); |
||
52 | api.getEditToken() |
||
53 | .then( |
||
54 | function ( token ) { |
||
55 | |||
56 | data.formData = { |
||
57 | format: 'json', |
||
58 | action: 'upload', |
||
59 | token: token, |
||
60 | ignorewarnings: 1, |
||
61 | comment: mw.message( 'simplebatchupload-comment' ).text(), |
||
62 | filename: data.files[ 0 ].name |
||
63 | }; |
||
64 | |||
65 | data.submit() |
||
66 | .success( function ( result /*, textStatus, jqXHR */ ) { |
||
67 | |||
68 | if ( result.error !== undefined ) { |
||
69 | |||
70 | status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
||
71 | |||
72 | } else { |
||
73 | var link = $( '<a>' ); |
||
74 | link |
||
75 | .attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
||
76 | .text( result.upload.filename ); |
||
77 | |||
78 | status |
||
79 | .addClass( 'ful-success' ) |
||
80 | .text( ' OK' ) |
||
81 | .prepend( link ); |
||
82 | } |
||
83 | |||
84 | } ) |
||
85 | .error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
||
86 | status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
||
87 | } ); |
||
88 | }, |
||
89 | function () { |
||
90 | status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
||
91 | } |
||
92 | ); |
||
93 | |||
94 | }, |
||
95 | |||
110 |