| Conditions | 3 |
| Paths | 2 |
| Total Lines | 56 |
| 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 | import path from 'path' |
||
| 74 | export function fromUrl(url) { |
||
| 75 | var res = { |
||
| 76 | root: '', |
||
| 77 | draft: { |
||
| 78 | dir: '', |
||
| 79 | file: '', |
||
| 80 | path: '' |
||
| 81 | }, |
||
| 82 | publish: { |
||
| 83 | dir: '', |
||
| 84 | file: '', |
||
| 85 | link: '', |
||
| 86 | path: '', |
||
| 87 | json: '' |
||
| 88 | }, |
||
| 89 | json: { |
||
| 90 | path: '', |
||
| 91 | file: '' |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | if(typeof url !== 'undefined' && url !== null) { |
||
| 96 | |||
| 97 | var dir = path.dirname(url).replace(config.root, '') |
||
| 98 | var filename = path.basename(url) |
||
| 99 | var link = url.replace(config.root, '') |
||
| 100 | link = link.replace(/^\//, '').split('/') |
||
| 101 | link.shift() |
||
| 102 | link = cmsData.fileAttr.delete('/' + link.join('/').replace(/\/$/, '')) |
||
| 103 | |||
| 104 | let draft = config.draft.url |
||
| 105 | let publish = config.publish.url |
||
| 106 | let data = config.data.url |
||
| 107 | |||
| 108 | res.root = config.root |
||
| 109 | |||
| 110 | // set dir path draft/json |
||
| 111 | res.draft.dir = FileParser.changePathEnv(path.join(config.root, dir), draft) |
||
| 112 | res.json.dir = FileParser.changePathEnv(path.join(config.root, dir), data) |
||
| 113 | res.publish.dir = FileParser.changePathEnv(path.join(config.root, dir), publish) |
||
| 114 | res.publish.json = res.json.dir |
||
| 115 | |||
| 116 | // set filename draft/json |
||
| 117 | res.draft.file = filename |
||
| 118 | res.publish.file = cmsData.fileAttr.delete(filename) |
||
| 119 | res.publish.link = link |
||
| 120 | res.json.file = filename.replace(`.${config.files.templates.extension}`, '.json') |
||
| 121 | res.publish.json = path.join(res.json.dir, cmsData.fileAttr.delete(res.json.file)) |
||
| 122 | |||
| 123 | // set filename draft/json |
||
| 124 | res.draft.path = path.join(res.draft.dir, res.draft.file) |
||
| 125 | res.publish.path = path.join(res.publish.dir, res.publish.file) |
||
| 126 | res.json.path = path.join(res.json.dir, res.json.file) |
||
| 127 | } |
||
| 128 | return res |
||
| 129 | } |