| Conditions | 4 |
| Paths | 6 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | $(function () { |
||
| 130 | function printPokemon(pokemon,pokeimg_suffix){ |
||
| 131 | var trainerPokemon = $('<div>',{id : 'trainerPokemon_'+pokemon.pokemon_uid, class: "col-md-1 col-xs-4 pokemon-single", style: "text-align: center" }); |
||
| 132 | var gymClass = ""; |
||
| 133 | if ((pokemon.gym_id===null)) { |
||
| 134 | gymClass = "unseen"; |
||
| 135 | } |
||
| 136 | trainerPokemon.append( |
||
| 137 | $('<a>', |
||
| 138 | {href : 'pokemon/'+pokemon.pokemon_id} |
||
| 139 | ).append($('<img />', |
||
| 140 | { src : 'core/pokemons/'+pokemon.pokemon_id+pokeimg_suffix, |
||
| 141 | 'class' : 'img-responsive '+gymClass |
||
| 142 | }) |
||
| 143 | ) |
||
| 144 | ); |
||
| 145 | trainerPokemon.append($('<p>',{class : 'pkmn-name'}).append(pokemon.cp)); |
||
| 146 | var progressBar = $('<div>',{class : 'progress'}).css({'height': '6px','margin-bottom': '0'}); |
||
| 147 | progressBar.append( |
||
| 148 | $('<div>', |
||
| 149 | { |
||
| 150 | title: 'IV Stamina :'+pokemon.iv_stamina, |
||
| 151 | class: 'progress-bar progress-bar-success' , |
||
| 152 | role : 'progressbar', |
||
| 153 | 'aria-valuenow' :pokemon.iv_stamina, |
||
| 154 | 'aria-valuemin' : 0, |
||
| 155 | 'aria-valuemax' : 45 |
||
| 156 | }).css('width',((100/45)*pokemon.iv_stamina ) + '%')) |
||
| 157 | progressBar.append( |
||
| 158 | $('<div>', |
||
| 159 | { |
||
| 160 | title: 'IV Attack :'+pokemon.iv_attack, |
||
| 161 | class: 'progress-bar progress-bar-danger' , |
||
| 162 | role : 'progressbar', |
||
| 163 | 'aria-valuenow' : pokemon.iv_attack, |
||
| 164 | 'aria-valuemin' : 0, |
||
| 165 | 'aria-valuemax' : 45 |
||
| 166 | }).css('width',((100/45)*pokemon.iv_attack ) + '%')) |
||
| 167 | progressBar.append( |
||
| 168 | $('<div>', |
||
| 169 | { |
||
| 170 | title: 'IV Defense :'+pokemon.iv_defense, |
||
| 171 | class: 'progress-bar progress-bar-info' , |
||
| 172 | role : 'progressbar', |
||
| 173 | 'aria-valuenow': pokemon.iv_defense, |
||
| 174 | 'aria-valuemin' : 0, |
||
| 175 | 'aria-valuemax' : 45 |
||
| 176 | }).css('width',((100/45)*pokemon.iv_defense ) + '%')) |
||
| 177 | trainerPokemon.append(progressBar); |
||
| 178 | if (pokemon.last_scanned === '0') { |
||
| 179 | trainerPokemon.append($('<small>',{text: "Today"})); |
||
| 180 | } |
||
| 181 | else if (pokemon.last_scanned === '1') { |
||
| 182 | trainerPokemon.append($('<small>',{text: pokemon.last_scanned + " Day"})); |
||
| 183 | } |
||
| 184 | else { |
||
| 185 | trainerPokemon.append($('<small>',{text: pokemon.last_scanned + " Days"})); |
||
| 186 | } |
||
| 187 | return trainerPokemon; |
||
| 188 | } |