| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 | /** global: Analytics */ |
||
| 7 | responseToDataTable: function(response, localeDefinition) { |
||
| 8 | var dataTable = new google.visualization.DataTable(); |
||
| 9 | |||
| 10 | |||
| 11 | // Columns |
||
| 12 | |||
| 13 | $.each(response.cols, function(key, column) { |
||
| 14 | var dataTableColumnType; |
||
| 15 | |||
| 16 | switch (column.type) { |
||
| 17 | case 'date': |
||
| 18 | dataTableColumnType = 'date'; |
||
| 19 | break; |
||
| 20 | case 'percent': |
||
| 21 | case 'time': |
||
| 22 | case 'integer': |
||
| 23 | case 'currency': |
||
| 24 | case 'float': |
||
| 25 | dataTableColumnType = 'number'; |
||
| 26 | break; |
||
| 27 | |||
| 28 | default: |
||
| 29 | dataTableColumnType = 'string'; |
||
| 30 | } |
||
| 31 | |||
| 32 | dataTable.addColumn({ |
||
| 33 | type: dataTableColumnType, |
||
| 34 | label: column.label, |
||
| 35 | id: column.id, |
||
| 36 | }); |
||
| 37 | }); |
||
| 38 | |||
| 39 | |||
| 40 | // Rows |
||
| 41 | |||
| 42 | $.each(response.rows, $.proxy(function(keyRow, row) { |
||
| 43 | |||
| 44 | var dataTableRow = []; |
||
| 45 | |||
| 46 | $.each(response.cols, $.proxy(function(keyColumn, column) { |
||
| 47 | switch (column.type) { |
||
| 48 | case 'date': |
||
| 49 | dataTableRow[keyColumn] = Analytics.Utils.formatByType(localeDefinition, column.type, row[keyColumn]); |
||
| 50 | break; |
||
| 51 | |||
| 52 | case 'float': |
||
| 53 | dataTableRow[keyColumn] = +row[keyColumn]; |
||
| 54 | break; |
||
| 55 | |||
| 56 | case 'integer': |
||
| 57 | case 'currency': |
||
| 58 | case 'percent': |
||
| 59 | case 'time': |
||
| 60 | case 'continent': |
||
| 61 | case 'subContinent': |
||
| 62 | dataTableRow[keyColumn] = { |
||
| 63 | v: Analytics.Utils.formatRawValueByType(localeDefinition, column.type, row[keyColumn]), |
||
| 64 | f: Analytics.Utils.formatByType(localeDefinition, column.type, row[keyColumn]) |
||
| 65 | }; |
||
| 66 | break; |
||
| 67 | |||
| 68 | default: |
||
| 69 | dataTableRow[keyColumn] = row[keyColumn]; |
||
| 70 | } |
||
| 71 | }, this)); |
||
| 72 | |||
| 73 | dataTable.addRow(dataTableRow); |
||
| 74 | |||
| 75 | }, this)); |
||
| 76 | |||
| 77 | return dataTable; |
||
| 78 | }, |
||
| 79 | |||
| 193 |