Conditions | 1 |
Paths | 1 |
Total Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 | /** |
||
25 | ;( function ( $, mw, undefined ) { |
||
26 | |||
27 | 'use strict'; |
||
28 | |||
29 | $( function () { |
||
30 | $( '#fileupload' ) |
||
31 | |||
32 | .on( 'change', function ( e, data ) { $( '#fileupload-results' ).empty(); } ) |
||
33 | |||
34 | .fileupload( { |
||
35 | dataType: 'json', |
||
36 | dropZone: $( '#fileupload-dropzone' ), |
||
37 | progressInterval: 100, |
||
38 | |||
39 | drop: function ( e, data ) { |
||
40 | $( '#fileupload-results' ).empty(); |
||
41 | }, |
||
42 | |||
43 | add: function ( e, data ) { |
||
44 | |||
45 | data.id = Date.now(); |
||
46 | |||
47 | var status = $('<li>') |
||
48 | .attr( 'id', data.id ) |
||
49 | .text( data.files[0].name ); |
||
50 | $( '#fileupload-results' ).append( status ); |
||
51 | |||
52 | data.formData = { |
||
53 | format: 'json', |
||
54 | action: 'upload', |
||
55 | token: $( this ).fileupload( 'option', 'token' ), |
||
56 | ignorewarnings: 1, |
||
57 | filename: data.files[ 0 ].name |
||
58 | }; |
||
59 | |||
60 | data.submit() |
||
61 | .success( function ( result /*, textStatus, jqXHR */ ) { |
||
62 | |||
63 | if ( result.error != undefined ) { |
||
64 | |||
65 | status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
||
66 | |||
67 | } else { |
||
68 | var link = $( '<a>' ); |
||
69 | link |
||
70 | .attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
||
71 | .text( result.upload.filename ); |
||
72 | |||
73 | status |
||
74 | .addClass( 'ful-success' ) |
||
75 | .text( ' OK' ) |
||
76 | .prepend( link ); |
||
77 | } |
||
78 | |||
79 | } ) |
||
80 | .error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
||
81 | status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
||
82 | } ); |
||
83 | |||
84 | }, |
||
85 | |||
86 | progress: function (e, data) { |
||
87 | if ( data.loaded != data.total ) { |
||
88 | $( '#' + data.id ) |
||
89 | .text( data.files[0].name + ' ' + parseInt(data.loaded / data.total * 100, 10) + '%' ); |
||
90 | } |
||
91 | } |
||
92 | } ); |
||
93 | |||
94 | $( document ).bind( 'drop dragover', function ( e ) { |
||
95 | e.preventDefault(); |
||
96 | } ); |
||
97 | } ); |
||
98 | |||
99 | }( jQuery, mediaWiki )); |
||
100 |
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.