| Total Complexity | 16 |
| Complexity/F | 2 |
| Lines of Code | 65 |
| Function Count | 8 |
| Duplicated Lines | 65 |
| Ratio | 100 % |
| Changes | 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 | fileUtils, |
||
| 3 | cmsOperations, |
||
| 4 | cleanSlug, |
||
| 5 | Hooks, |
||
| 6 | Manager |
||
| 7 | } from '../../cli' |
||
| 8 | |||
| 9 | var route = function(req, res, next){ |
||
| 10 | Hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 11 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
| 12 | |||
| 13 | var filePath = cleanSlug(req.body.filePath) |
||
| 14 | var p = new Promise((resolve) => { |
||
| 15 | cmsOperations.save.save( |
||
| 16 | fileUtils.getFilePath(filePath), |
||
| 17 | req.body.tplPath, |
||
| 18 | req.body.json, |
||
| 19 | '', |
||
| 20 | 'draft', |
||
| 21 | null, |
||
| 22 | 'publish') |
||
| 23 | .then(() => { |
||
| 24 | resolve() |
||
| 25 | }).catch(function(e) { |
||
| 26 | console.error(e) |
||
| 27 | }) |
||
| 28 | }) |
||
| 29 | |||
| 30 | p.then((resSave) => { |
||
| 31 | cmsOperations.save.save( |
||
| 32 | fileUtils.getFilePath(req.body.filePath), |
||
| 33 | req.body.tplPath, |
||
| 34 | req.body.json, |
||
| 35 | '', |
||
| 36 | 'publish', |
||
| 37 | resSave, |
||
| 38 | 'publish') |
||
| 39 | .then((resSave) => { |
||
| 40 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 41 | res.set('Content-Type', 'application/json') |
||
| 42 | res.send(JSON.stringify({error: resSave.error})) |
||
| 43 | } |
||
| 44 | var result |
||
| 45 | if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 46 | result = resSave |
||
| 47 | } |
||
| 48 | if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 49 | result = { |
||
| 50 | success: 1, |
||
| 51 | json: resSave.json |
||
| 52 | } |
||
| 53 | } |
||
| 54 | Manager.instance.updateList() |
||
| 55 | res.set('Content-Type', 'application/json') |
||
| 56 | res.send(JSON.stringify(result)) |
||
| 57 | }).catch(function(e) { |
||
| 58 | console.error('post-publish.js', e) |
||
| 59 | }) |
||
| 60 | }).catch(function(e) { |
||
| 61 | console.error('post-publish.js', e) |
||
| 62 | }) |
||
| 63 | } |
||
| 64 | |||
| 65 | export default route |