| Conditions | 1 |
| Paths | 8 |
| Total Lines | 57 |
| Lines | 57 |
| Ratio | 100 % |
| Changes | 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 | import path from 'path' |
||
| 108 | View Code Duplication | export function reject(filePath, tplPath, json) { |
|
| 109 | abeExtend.hooks.instance.trigger('beforeReject', filePath) |
||
| 110 | |||
| 111 | var p = new Promise((resolve) => { |
||
| 112 | cmsOperations.save.save( |
||
| 113 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 114 | tplPath, |
||
| 115 | json, |
||
| 116 | '', |
||
| 117 | 'draft', |
||
| 118 | null, |
||
| 119 | 'reject') |
||
| 120 | .then(() => { |
||
| 121 | resolve() |
||
| 122 | }).catch(function(e) { |
||
| 123 | console.error(e) |
||
| 124 | }) |
||
| 125 | }) |
||
| 126 | |||
| 127 | p.then((resSave) => { |
||
| 128 | cmsOperations.save.save( |
||
| 129 | path.join(config.root, config.draft.url, filePath.replace(config.root)), |
||
| 130 | tplPath, |
||
| 131 | json, |
||
| 132 | '', |
||
| 133 | 'reject', |
||
| 134 | resSave, |
||
| 135 | 'reject') |
||
| 136 | .then((resSave) => { |
||
| 137 | var result |
||
| 138 | if(typeof resSave.error !== 'undefined' && resSave.error !== null ){ |
||
| 139 | result = { |
||
| 140 | success: 0, |
||
| 141 | error: resSave.error |
||
| 142 | } |
||
| 143 | } else if(typeof resSave.reject !== 'undefined' && resSave.reject !== null){ |
||
| 144 | result = resSave |
||
| 145 | } else if(typeof resSave.json !== 'undefined' && resSave.json !== null){ |
||
| 146 | result = { |
||
| 147 | success: 1, |
||
| 148 | json: resSave.json |
||
| 149 | } |
||
| 150 | } |
||
| 151 | abeExtend.hooks.instance.trigger('afterReject', result) |
||
| 152 | Manager.instance.updateList() |
||
| 153 | resolve(result) |
||
| 154 | }) |
||
| 155 | }).catch(function(e) { |
||
| 156 | console.error(e) |
||
| 157 | var result = { |
||
| 158 | success: 0, |
||
| 159 | error: 'reject error' |
||
| 160 | } |
||
| 161 | abeExtend.hooks.instance.trigger('afterReject', result) |
||
| 162 | resolve(result) |
||
| 163 | }) |
||
| 164 | } |