| Conditions | 2 |
| Paths | 4 |
| Total Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 | /** |
||
| 147 | let getViewForSwagger1 = function (opts) { |
||
| 148 | let swagger = opts.swagger |
||
| 149 | let data = { |
||
| 150 | description: swagger.description, |
||
| 151 | moduleName: opts.moduleName, |
||
| 152 | className: opts.className, |
||
| 153 | domain: swagger.basePath ? swagger.basePath : '', |
||
| 154 | methods: [] |
||
| 155 | } |
||
| 156 | swagger.apis.forEach(function (api) { |
||
| 157 | api.operations.forEach(function (op) { |
||
| 158 | let method = { |
||
| 159 | path: api.path, |
||
| 160 | className: opts.className, |
||
| 161 | methodName: op.nickname, |
||
| 162 | method: op.method, |
||
| 163 | isGET: op.method === 'GET', |
||
| 164 | isPOST: op.method.toUpperCase() === 'POST', |
||
| 165 | summary: op.summary, |
||
| 166 | parameters: op.parameters, |
||
| 167 | headers: [] |
||
| 168 | } |
||
| 169 | |||
| 170 | if (op.produces) { |
||
| 171 | let headers = [] |
||
| 172 | headers.value = [] |
||
| 173 | |||
| 174 | headers.name = 'Accept' |
||
| 175 | headers.value.push(op.produces.map(function (value) { return '\'' + value + '\'' }).join(', ')) |
||
| 176 | |||
| 177 | method.headers.push(headers) |
||
| 178 | } |
||
| 179 | |||
| 180 | op.parameters = op.parameters ? op.parameters : [] |
||
| 181 | op.parameters.forEach(function (parameter) { |
||
| 182 | parameter.camelCaseName = _.camelCase(parameter.name) |
||
| 183 | if (parameter.enum && parameter.enum.length === 1) { |
||
| 184 | parameter.isSingleton = true |
||
| 185 | parameter.singleton = parameter.enum[0] |
||
| 186 | } |
||
| 187 | if (parameter.paramType === 'body') { |
||
| 188 | parameter.isBodyParameter = true |
||
| 189 | } else if (parameter.paramType === 'path') { |
||
| 190 | parameter.isPathParameter = true |
||
| 191 | } else if (parameter.paramType === 'query') { |
||
| 192 | if (parameter['x-name-pattern']) { |
||
| 193 | parameter.isPatternType = true |
||
| 194 | parameter.pattern = parameter['x-name-pattern'] |
||
| 195 | } |
||
| 196 | parameter.isQueryParameter = true |
||
| 197 | } else if (parameter.paramType === 'header') { |
||
| 198 | parameter.isHeaderParameter = true |
||
| 199 | } else if (parameter.paramType === 'form') { |
||
| 200 | parameter.isFormParameter = true |
||
| 201 | } |
||
| 202 | }) |
||
| 203 | data.methods.push(method) |
||
| 204 | }) |
||
| 205 | }) |
||
| 206 | return data |
||
| 207 | } |
||
| 208 | |||
| 215 |