| Conditions | 5 |
| Paths | 8 |
| Total Lines | 62 |
| 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 printInput from './printInput' |
||
| 4 | export default function printBlock (ctx) { |
||
| 5 | var res = '' |
||
| 6 | |||
| 7 | if(typeof ctx[0].block !== 'undefined' && ctx[0].block !== null && ctx[0].block !== '') { |
||
| 8 | res += `<div class="form-group"> |
||
| 9 | <label class="title">${ctx[0].block}</label> |
||
| 10 | <div class='single-block well well-sm'>` |
||
| 11 | Array.prototype.forEach.call(ctx, (item) => { |
||
| 12 | res += printInput(item) |
||
| 13 | }) |
||
| 14 | res += '</div></div>' |
||
| 15 | }else if(ctx[0].key.indexOf('[') > -1) { |
||
| 16 | var ctxBlock = ctx[0].key.split('[')[0] |
||
| 17 | res += `<div class="form-group"> |
||
| 18 | <div class="list-group" data-block="${ctxBlock}" > |
||
| 19 | <label> |
||
| 20 | ${ctxBlock} |
||
| 21 | <button type="button" class="btn btn-success add-block" title="Add new block" > |
||
| 22 | <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> |
||
| 23 | </button> |
||
| 24 | </label>` |
||
| 25 | |||
| 26 | var arrItem = [] |
||
| 27 | Array.prototype.forEach.call(ctx, (item) => { |
||
| 28 | var index = item.key.match(/[^\[\]]+?(?=\])/) |
||
| 29 | if(typeof arrItem[index] === 'undefined' || arrItem[index] === null) { |
||
| 30 | arrItem[index] = [] |
||
| 31 | } |
||
| 32 | arrItem[index].push(item) |
||
| 33 | }) |
||
| 34 | |||
| 35 | Array.prototype.forEach.call(Object.keys(arrItem), (i) => { |
||
| 36 | var key = arrItem[i][0].key.split('[')[0] |
||
| 37 | var display = '' |
||
| 38 | if(typeof abeEngine.instance.content[key] === 'undefined' || abeEngine.instance.content[key] === null |
||
| 39 | || abeEngine.instance.content[key].length === 0) { |
||
| 40 | display = 'style="display: none"' |
||
| 41 | } |
||
| 42 | res += `<div class="list-block" data-block="${key}${i}" ${display}> |
||
| 43 | <button type="button" class="btn btn-info collapsed" data-toggle="collapse" data-target="#${key}${i}" > |
||
| 44 | Section <span class='label-count'>${i}</span> : |
||
| 45 | <span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span> |
||
| 46 | </button> |
||
| 47 | <button type="button" class="btn btn-danger remove-block" title="Delete block" > |
||
| 48 | <span class="glyphicon glyphicon-trash" aria-hidden="true"></span> |
||
| 49 | </button> |
||
| 50 | <div id="${key}${i}" class="collapse" > |
||
| 51 | ` |
||
| 52 | Array.prototype.forEach.call(arrItem[i], (item) => { |
||
| 53 | res += printInput(item) |
||
| 54 | }) |
||
| 55 | res += '</div></div>' |
||
| 56 | }) |
||
| 57 | |||
| 58 | res += ` |
||
| 59 | </div> |
||
| 60 | </div>` |
||
| 61 | }else { |
||
| 62 | res += printInput(ctx[0]) |
||
| 63 | } |
||
| 64 | return res |
||
| 65 | } |
||
| 66 |