| Conditions | 1 |
| Paths | 4 |
| Total Lines | 81 |
| 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 | /** Global: trainerName */ |
||
| 4 | $.getJSON( "core/json/variables.json", function( jsondata ) { |
||
| 5 | var pokeimg_suffix=jsondata['system']['pokeimg_suffix']; |
||
| 6 | |||
| 7 | $('.trainerLoader').hide(); |
||
| 8 | var page = 0; |
||
| 9 | var teamSelector=0; //0=all;1=Blue;2=Red;3=Yellow |
||
| 10 | var rankingFilter=0; //0=Level & Gyms; 1=Level; 2=Gyms |
||
| 11 | |||
| 12 | $('input#name').val(trainerName); |
||
| 13 | loadTrainers(page,$('input#name').val(),null,null,pokeimg_suffix,true); |
||
| 14 | |||
| 15 | page++; |
||
| 16 | var win = $(window); |
||
| 17 | win.scroll(function () { |
||
| 18 | // End of the document reached? |
||
| 19 | if ($(document).height() - win.height() == win.scrollTop()) { |
||
| 20 | loadTrainers(page,$('input#name').val(),teamSelector,rankingFilter,pokeimg_suffix,true); |
||
| 21 | page++; |
||
| 22 | } |
||
| 23 | }); |
||
| 24 | $("#searchTrainer").submit(function ( event ) { |
||
| 25 | page = 0; |
||
| 26 | $('input#name').val()!=''?$('#trainersGraph').hide():$('#trainersGraph').show(); |
||
| 27 | $('#trainersContainer tr:not(.trainersTemplate)').remove(); |
||
| 28 | loadTrainers(page,$('input#name').val(),teamSelector,rankingFilter,pokeimg_suffix,true); |
||
| 29 | page++; |
||
| 30 | event.preventDefault(); |
||
| 31 | }); |
||
| 32 | $(".teamSelectorItems").click(function ( event ) { |
||
| 33 | switch ($(this).attr("id")) { |
||
| 34 | case "AllTeamsFilter": |
||
| 35 | teamSelector=0; |
||
| 36 | break; |
||
| 37 | case "BlueTeamFilter": |
||
| 38 | teamSelector=1; |
||
| 39 | break; |
||
| 40 | case "RedTeamFilter": |
||
| 41 | teamSelector=2; |
||
| 42 | break; |
||
| 43 | case "YellowFilter": |
||
| 44 | teamSelector=3; |
||
| 45 | break; |
||
| 46 | default: |
||
| 47 | teamSelector=0; |
||
| 48 | } |
||
| 49 | $("#teamSelectorText").html($(this).html()); |
||
| 50 | event.preventDefault(); |
||
| 51 | $("#searchTrainer").submit(); |
||
| 52 | |||
| 53 | }); |
||
| 54 | $(".rankingOrderItems").click(function ( event ) { |
||
| 55 | switch ($(this).attr("id")) { |
||
| 56 | case "levelsFirst": |
||
| 57 | rankingFilter=0; |
||
| 58 | break; |
||
| 59 | case "gymsFirst": |
||
| 60 | rankingFilter=1; |
||
| 61 | break; |
||
| 62 | case "maxCpFirst": |
||
| 63 | rankingFilter=2; |
||
| 64 | break; |
||
| 65 | default: |
||
| 66 | rankingFilter=0; |
||
| 67 | } |
||
| 68 | $("#rankingOrderText").html($(this).html()); |
||
| 69 | event.preventDefault(); |
||
| 70 | $("#searchTrainer").submit(); |
||
| 71 | |||
| 72 | }); |
||
| 73 | window.onpopstate = function(event) { |
||
|
|
|||
| 74 | if (window.history.state && "Trainer" === window.history.state.page) { |
||
| 75 | $('#trainersContainer').empty(); |
||
| 76 | $('input#name').val(window.history.state.name); |
||
| 77 | loadTrainers(0,$('input#name').val(),teamSelector,rankingFilter,pokeimg_suffix, false); |
||
| 78 | } |
||
| 79 | else{ |
||
| 80 | history.back(); |
||
| 81 | } |
||
| 82 | }; |
||
| 83 | |||
| 84 | }); |
||
| 85 | }); |
||
| 211 |
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.