| Conditions | 1 |
| Paths | 2 |
| Total Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 | 'use strict'; |
||
| 16 | analyze: url => { |
||
| 17 | const wappalyzer = new Wappalyzer(); |
||
| 18 | |||
| 19 | wappalyzer.apps = json.apps; |
||
| 20 | wappalyzer.categories = json.categories; |
||
| 21 | |||
| 22 | return new Promise((resolve, reject) => { |
||
| 23 | wappalyzer.driver.log = (message, source, type) => { |
||
| 24 | if ( type === 'error' ) { |
||
| 25 | return reject(message); |
||
| 26 | } |
||
| 27 | |||
| 28 | if ( !driver.quiet ) { |
||
| 29 | console.log('[wappalyzer ' + type + ']', '[' + source + ']', message); |
||
| 30 | } |
||
| 31 | }; |
||
| 32 | |||
| 33 | wappalyzer.driver.displayApps = detected => { |
||
| 34 | var apps = []; |
||
| 35 | |||
| 36 | Object.keys(detected).forEach(appName => { |
||
| 37 | const app = detected[appName]; |
||
| 38 | |||
| 39 | var categories = []; |
||
| 40 | |||
| 41 | app.props.cats.forEach(id => { |
||
| 42 | var category = {}; |
||
| 43 | |||
| 44 | category[id] = wappalyzer.categories[id].name; |
||
| 45 | |||
| 46 | categories.push(category) |
||
| 47 | }); |
||
| 48 | |||
| 49 | apps.push({ |
||
| 50 | name: app.name, |
||
| 51 | confidence: app.confidenceTotal.toString(), |
||
| 52 | version: app.version, |
||
| 53 | icon: app.props.icon || 'default.svg', |
||
| 54 | website: app.props.website, |
||
| 55 | categories |
||
| 56 | }); |
||
| 57 | }); |
||
| 58 | |||
| 59 | resolve(apps); |
||
| 60 | }; |
||
| 61 | |||
| 62 | const browser = new Browser(); |
||
| 63 | |||
| 64 | browser.visit(url, error => { |
||
| 65 | if ( !browser.resources['0'].response ) { |
||
| 66 | return reject('No response from server'); |
||
| 67 | } |
||
| 68 | |||
| 69 | browser.wait(options.maxWait) |
||
| 70 | .then(() => { |
||
| 71 | wappalyzer.driver.document = browser.document; |
||
| 72 | |||
| 73 | const headers = {}; |
||
| 74 | |||
| 75 | browser.resources['0'].response.headers._headers.forEach(header => { |
||
| 76 | headers[header[0]] = header[1]; |
||
| 77 | }); |
||
| 78 | |||
| 79 | const vars = Object.getOwnPropertyNames(browser.window); |
||
| 80 | const html = browser.html(); |
||
| 81 | |||
| 82 | const hostname = wappalyzer.parseUrl(url).hostname; |
||
| 83 | |||
| 84 | wappalyzer.analyze(hostname, url, { |
||
| 85 | headers, |
||
| 86 | html, |
||
| 87 | env: vars |
||
| 88 | }); |
||
| 89 | }) |
||
| 90 | .catch(error => reject(error)); |
||
| 91 | }); |
||
| 92 | }); |
||
| 93 | } |
||
| 94 | }; |
||
| 98 |