| Conditions | 1 |
| Paths | 12 |
| Total Lines | 74 |
| Lines | 0 |
| Ratio | 0 % |
| 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' |
||
| 141 | export function getFilesMerged(files) { |
||
| 142 | var merged = {} |
||
| 143 | var arMerged = [] |
||
| 144 | |||
| 145 | Array.prototype.forEach.call(files, (file) => { |
||
| 146 | var cleanFilePath = file.cleanFilePath |
||
| 147 | |||
| 148 | var fileStatusIsPublish = cmsData.fileAttr.get(file.cleanPath) |
||
| 149 | if(typeof fileStatusIsPublish.s !== 'undefined' && fileStatusIsPublish.s !== null && file.abe_meta.status === 'publish') { |
||
| 150 | file.abe_meta.status = 'draft' |
||
| 151 | } |
||
| 152 | |||
| 153 | file.html = path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)) |
||
| 154 | if (file.abe_meta.status === 'publish') { |
||
| 155 | file.htmlPath = path.join(config.root, config.publish.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 156 | }else { |
||
| 157 | file.htmlPath = path.join(config.root, config.draft.url, path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 158 | } |
||
| 159 | |||
| 160 | if(typeof merged[cleanFilePath] === 'undefined' || merged[cleanFilePath] === null) { |
||
| 161 | merged[cleanFilePath] = { |
||
| 162 | name: cmsData.fileAttr.delete(file.name) |
||
| 163 | , path: cmsData.fileAttr.delete(file.path) |
||
| 164 | , html: cmsData.fileAttr.delete(path.join('/', file.filePath.replace(/\.json/, `.${config.files.templates.extension}`))) |
||
| 165 | , htmlPath: path.join(config.root, config.publish.url, path.join('/', cmsData.fileAttr.delete(file.filePath.replace(/\.json/, `.${config.files.templates.extension}`)))) |
||
| 166 | , cleanPathName: file.cleanPathName |
||
| 167 | , cleanPath: file.cleanPath |
||
| 168 | , cleanName: file.cleanName |
||
| 169 | , cleanNameNoExt: file.cleanNameNoExt |
||
| 170 | , cleanFilePath: file.cleanFilePath |
||
| 171 | , filePath: cmsData.fileAttr.delete(file.filePath) |
||
| 172 | , revisions: [] |
||
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | merged[cleanFilePath].revisions.push(JSON.parse(JSON.stringify(file))) |
||
| 177 | }) |
||
| 178 | |||
| 179 | // return merged |
||
| 180 | Array.prototype.forEach.call(Object.keys(merged), (key) => { |
||
| 181 | var revisions = merged[key].revisions |
||
| 182 | revisions.sort(FileParser.predicatBy('date', -1)) |
||
| 183 | if(typeof revisions[0] !== 'undefined' && revisions[0] !== null) { |
||
| 184 | merged[key].date = revisions[0].date |
||
| 185 | } |
||
| 186 | |||
| 187 | Array.prototype.forEach.call(revisions, (revision) => { |
||
| 188 | |||
| 189 | var status = revision.abe_meta.status |
||
| 190 | |||
| 191 | if (status === 'publish') { |
||
| 192 | merged[key][status] = revision |
||
| 193 | }else { |
||
| 194 | merged[key][status] = {} |
||
| 195 | } |
||
| 196 | merged[key][status].path = revision.path |
||
| 197 | merged[key][status].html = revision.html |
||
| 198 | merged[key][status].htmlPath = revision.htmlPath |
||
| 199 | merged[key][status].date = new Date(revision.date) |
||
| 200 | merged[key][status].link = revision.abe_meta.link |
||
| 201 | }) |
||
| 202 | |||
| 203 | merged[key].revisions = revisions |
||
| 204 | |||
| 205 | merged[key].date = revisions[0].date |
||
| 206 | merged[key].cleanDate = revisions[0].cleanDate |
||
| 207 | merged[key].duration = revisions[0].duration |
||
| 208 | merged[key].abe_meta = revisions[0].abe_meta |
||
| 209 | |||
| 210 | arMerged.push(merged[key]) |
||
| 211 | }) |
||
| 212 | |||
| 213 | return arMerged |
||
| 214 | } |