| Conditions | 8 |
| Paths | 2 |
| Total Lines | 92 |
| 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 | /** global: chrome */ |
||
| 50 | function appsToDomTemplate(response) { |
||
| 51 | var |
||
| 52 | appName, confidence, version, categories, |
||
| 53 | template = []; |
||
| 54 | |||
| 55 | if ( response.tabCache && Object.keys(response.tabCache.detected).length > 0 ) { |
||
| 56 | const categories = {}; |
||
| 57 | |||
| 58 | // Group apps by category |
||
| 59 | for ( appName in response.tabCache.detected ) { |
||
| 60 | response.apps[appName].cats.forEach(cat => { |
||
| 61 | categories[cat] = categories[cat] || { apps: [] }; |
||
| 62 | |||
| 63 | categories[cat].apps[appName] = appName; |
||
| 64 | }); |
||
| 65 | } |
||
| 66 | |||
| 67 | for ( cat in categories ) { |
||
|
|
|||
| 68 | const apps = []; |
||
| 69 | |||
| 70 | for ( appName in categories[cat].apps ) { |
||
| 71 | confidence = response.tabCache.detected[appName].confidenceTotal; |
||
| 72 | version = response.tabCache.detected[appName].version; |
||
| 73 | |||
| 74 | apps.push( |
||
| 75 | [ |
||
| 76 | 'a', { |
||
| 77 | class: 'detected__app', |
||
| 78 | target: '_blank', |
||
| 79 | href: 'https://wappalyzer.com/applications/' + slugify(appName) |
||
| 80 | }, [ |
||
| 81 | 'img', { |
||
| 82 | class: 'detected__app-icon', |
||
| 83 | src: '../images/icons/' + ( response.apps[appName].icon || 'default.svg' ) |
||
| 84 | }, |
||
| 85 | ], [ |
||
| 86 | 'span', { |
||
| 87 | class: 'detected__app-name' |
||
| 88 | }, |
||
| 89 | appName + ( version ? ' ' + version : '' ) + ( confidence < 100 ? ' (' + confidence + '% sure)' : '' ) |
||
| 90 | ] |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | template.push( |
||
| 96 | [ |
||
| 97 | 'div', { |
||
| 98 | class: 'detected__category' |
||
| 99 | }, [ |
||
| 100 | 'a', { |
||
| 101 | class: 'detected__category-link', |
||
| 102 | target: '_blank', |
||
| 103 | href: 'https://wappalyzer.com/categories/' + slugify(response.categories[cat].name) |
||
| 104 | }, [ |
||
| 105 | 'span', { |
||
| 106 | class: 'detected__category-name' |
||
| 107 | }, |
||
| 108 | browser.i18n.getMessage('categoryName' + cat) |
||
| 109 | ] |
||
| 110 | ], [ |
||
| 111 | 'div', { |
||
| 112 | class: 'detected__apps' |
||
| 113 | }, |
||
| 114 | apps |
||
| 115 | ] |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | template = [ |
||
| 121 | 'div', { |
||
| 122 | class: 'detected' |
||
| 123 | }, |
||
| 124 | template |
||
| 125 | ]; |
||
| 126 | } else { |
||
| 127 | template = [ |
||
| 128 | 'div', { |
||
| 129 | class: 'empty' |
||
| 130 | }, |
||
| 131 | [ |
||
| 132 | 'span', { |
||
| 133 | class: 'empty__text' |
||
| 134 | }, |
||
| 135 | browser.i18n.getMessage('noAppsDetected') |
||
| 136 | ], |
||
| 137 | ]; |
||
| 138 | } |
||
| 139 | |||
| 140 | return template; |
||
| 141 | } |
||
| 142 | |||
| 146 |