| Total Complexity | 15 |
| Complexity/F | 2.14 |
| Lines of Code | 61 |
| Function Count | 7 |
| Duplicated Lines | 61 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | View Code Duplication | import { |
|
|
|
|||
| 2 | cmsOperations, |
||
| 3 | fileUtils, |
||
| 4 | Hooks, |
||
| 5 | Manager |
||
| 6 | } from '../../cli' |
||
| 7 | |||
| 8 | var route = function(req, res, next){ |
||
| 9 | Hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 10 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
| 11 | |||
| 12 | var p = new Promise((resolve) => { |
||
| 13 | cmsOperations.save.save( |
||
| 14 | fileUtils.getFilePath(req.body.filePath), |
||
| 15 | req.body.tplPath, |
||
| 16 | req.body.json, |
||
| 17 | '', |
||
| 18 | 'draft', |
||
| 19 | null, |
||
| 20 | 'reject') |
||
| 21 | .then(() => { |
||
| 22 | resolve() |
||
| 23 | }).catch(function(e) { |
||
| 24 | console.error(e) |
||
| 25 | }) |
||
| 26 | }) |
||
| 27 | |||
| 28 | p.then((resSave) => { |
||
| 29 | cmsOperations.save.save( |
||
| 30 | fileUtils.getFilePath(req.body.filePath), |
||
| 31 | req.body.tplPath, |
||
| 32 | req.body.json, |
||
| 33 | '', |
||
| 34 | 'reject', |
||
| 35 | resSave, |
||
| 36 | 'reject') |
||
| 37 | .then((resSave) => { |
||
| 38 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 39 | res.set('Content-Type', 'application/json') |
||
| 40 | res.send(JSON.stringify({error: resSave.error})) |
||
| 41 | } |
||
| 42 | var result |
||
| 43 | if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 44 | result = resSave |
||
| 45 | } |
||
| 46 | if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 47 | result = { |
||
| 48 | success: 1, |
||
| 49 | json: resSave.json |
||
| 50 | } |
||
| 51 | } |
||
| 52 | Manager.instance.updateList() |
||
| 53 | res.set('Content-Type', 'application/json') |
||
| 54 | res.send(JSON.stringify(result)) |
||
| 55 | }) |
||
| 56 | }).catch(function(e) { |
||
| 57 | console.error(e) |
||
| 58 | }) |
||
| 59 | } |
||
| 60 | |||
| 61 | export default route |