| Conditions | 7 |
| Paths | 16 |
| Total Lines | 91 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 */ |
||
| 172 | function printPokemon(pokemon, pokeimg_suffix, iv_numbers, locale) { |
||
| 173 | var gymClass = pokemon.gym_id === null ? ' unseen' : ''; |
||
| 174 | var trainerPokemon = $('<div>', { id: 'trainerPokemon_' + pokemon.pokemon_uid, class: 'col-md-1 col-xs-4 pokemon-single' + gymClass, style: 'text-align: center' }); |
||
| 175 | if (gymClass) { |
||
| 176 | trainerPokemon.hide(); |
||
| 177 | } |
||
| 178 | trainerPokemon.append( |
||
| 179 | $('<a>', { href: 'pokemon/' + pokemon.pokemon_id }).append($('<img />', { |
||
| 180 | src: 'core/pokemons/' + pokemon.pokemon_id + pokeimg_suffix, |
||
| 181 | 'class': 'img-responsive' + gymClass |
||
| 182 | })) |
||
| 183 | ); |
||
| 184 | trainerPokemon.append($('<p>', { class: 'pkmn-name' }).append(pokemon.cp)); |
||
| 185 | var progressBar |
||
| 186 | if (iv_numbers) { |
||
| 187 | progressBar = $('<div>', { class: 'progress' }).css({ 'height': '15px', 'margin-bottom': '0' }); |
||
| 188 | progressBar.append( |
||
| 189 | $('<div>', { |
||
| 190 | title: locale.ivAttack + ' :' + pokemon.iv_attack, |
||
| 191 | class: 'progress-bar progress-bar-danger', |
||
| 192 | role: 'progressbar', |
||
| 193 | text: pokemon.iv_attack, |
||
| 194 | 'aria-valuenow': pokemon.iv_attack, |
||
| 195 | 'aria-valuemin': 0, |
||
| 196 | 'aria-valuemax': 45 |
||
| 197 | }).css({ 'width': (100 / 3) + '%', 'line-height': '16px' })) |
||
| 198 | progressBar.append( |
||
| 199 | $('<div>', { |
||
| 200 | title: locale.ivDefense + ' :' + pokemon.iv_defense, |
||
| 201 | class: 'progress-bar progress-bar-info', |
||
| 202 | role: 'progressbar', |
||
| 203 | text: pokemon.iv_defense, |
||
| 204 | 'aria-valuenow': pokemon.iv_defense, |
||
| 205 | 'aria-valuemin': 0, |
||
| 206 | 'aria-valuemax': 45 |
||
| 207 | }).css({ 'width': (100 / 3) + '%', 'line-height': '16px' })) |
||
| 208 | progressBar.append( |
||
| 209 | $('<div>', { |
||
| 210 | title: locale.ivStamina + ' :' + pokemon.iv_stamina, |
||
| 211 | class: 'progress-bar progress-bar-success', |
||
| 212 | role: 'progressbar', |
||
| 213 | text: pokemon.iv_stamina, |
||
| 214 | 'aria-valuenow': pokemon.iv_stamina, |
||
| 215 | 'aria-valuemin': 0, |
||
| 216 | 'aria-valuemax': 45 |
||
| 217 | }).css({ 'width': (100 / 3) + '%', 'line-height': '16px' })) |
||
| 218 | } else { |
||
| 219 | progressBar = $('<div>', { class: 'progress' }).css({ 'height': '6px', 'margin-bottom': '0' }); |
||
| 220 | progressBar.append( |
||
| 221 | $('<div>', { |
||
| 222 | title: locale.ivAttack + ' :' + pokemon.iv_attack, |
||
| 223 | class: 'progress-bar progress-bar-danger', |
||
| 224 | role: 'progressbar', |
||
| 225 | 'aria-valuenow': pokemon.iv_attack, |
||
| 226 | 'aria-valuemin': 0, |
||
| 227 | 'aria-valuemax': 45 |
||
| 228 | }).css('width', ((100 / 45) * pokemon.iv_attack) + '%')) |
||
| 229 | progressBar.append( |
||
| 230 | $('<div>', { |
||
| 231 | title: locale.ivDefense + ' :' + pokemon.iv_defense, |
||
| 232 | class: 'progress-bar progress-bar-info', |
||
| 233 | role: 'progressbar', |
||
| 234 | 'aria-valuenow': pokemon.iv_defense, |
||
| 235 | 'aria-valuemin': 0, |
||
| 236 | 'aria-valuemax': 45 |
||
| 237 | }).css('width', ((100 / 45) * pokemon.iv_defense) + '%')) |
||
| 238 | progressBar.append( |
||
| 239 | $('<div>', { |
||
| 240 | title: locale.ivStamina + ' :' + pokemon.iv_stamina, |
||
| 241 | class: 'progress-bar progress-bar-success', |
||
| 242 | role: 'progressbar', |
||
| 243 | 'aria-valuenow': pokemon.iv_stamina, |
||
| 244 | 'aria-valuemin': 0, |
||
| 245 | 'aria-valuemax': 45 |
||
| 246 | }).css('width', ((100 / 45) * pokemon.iv_stamina) + '%')) |
||
| 247 | } |
||
| 248 | trainerPokemon.append(progressBar); |
||
| 249 | if (pokemon.deployment_time) { |
||
| 250 | var diff = (new Date() - new Date(pokemon.deployment_time.replace(/-/g, '/'))) / 1000; |
||
| 251 | if (diff >= 86400) { |
||
| 252 | trainerPokemon.append($('<small>', { text: parseInt(diff / 86400) + 'd ' + parseInt((diff / 3600) % 24) + 'h'})); |
||
| 253 | } else { |
||
| 254 | trainerPokemon.append($('<small>', { text: parseInt(diff / 3600) + 'h ' + parseInt((diff / 60) % 60) + 'm' })); |
||
| 255 | } |
||
| 256 | } else if (pokemon.last_scanned === '1') { |
||
| 257 | trainerPokemon.append($('<small>', { text: pokemon.last_scanned + ' ' + locale.day })); |
||
| 258 | } else { |
||
| 259 | trainerPokemon.append($('<small>', { text: pokemon.last_scanned + ' ' + locale.days })); |
||
| 260 | } |
||
| 261 | return trainerPokemon; |
||
| 262 | } |
||
| 263 |