| Conditions | 37 |
| Total Lines | 81 |
| Code 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:
Complex classes like mysql.*mysqlField.typeDatabaseName often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | // Go MySQL Driver - A MySQL-Driver for Go's database/sql package |
||
| 16 | func (mf *mysqlField) typeDatabaseName() string { |
||
| 17 | switch mf.fieldType { |
||
| 18 | case fieldTypeBit: |
||
| 19 | return "BIT" |
||
| 20 | case fieldTypeBLOB: |
||
| 21 | if mf.charSet != collations[binaryCollation] { |
||
| 22 | return "TEXT" |
||
| 23 | } |
||
| 24 | return "BLOB" |
||
| 25 | case fieldTypeDate: |
||
| 26 | return "DATE" |
||
| 27 | case fieldTypeDateTime: |
||
| 28 | return "DATETIME" |
||
| 29 | case fieldTypeDecimal: |
||
| 30 | return "DECIMAL" |
||
| 31 | case fieldTypeDouble: |
||
| 32 | return "DOUBLE" |
||
| 33 | case fieldTypeEnum: |
||
| 34 | return "ENUM" |
||
| 35 | case fieldTypeFloat: |
||
| 36 | return "FLOAT" |
||
| 37 | case fieldTypeGeometry: |
||
| 38 | return "GEOMETRY" |
||
| 39 | case fieldTypeInt24: |
||
| 40 | return "MEDIUMINT" |
||
| 41 | case fieldTypeJSON: |
||
| 42 | return "JSON" |
||
| 43 | case fieldTypeLong: |
||
| 44 | return "INT" |
||
| 45 | case fieldTypeLongBLOB: |
||
| 46 | if mf.charSet != collations[binaryCollation] { |
||
| 47 | return "LONGTEXT" |
||
| 48 | } |
||
| 49 | return "LONGBLOB" |
||
| 50 | case fieldTypeLongLong: |
||
| 51 | return "BIGINT" |
||
| 52 | case fieldTypeMediumBLOB: |
||
| 53 | if mf.charSet != collations[binaryCollation] { |
||
| 54 | return "MEDIUMTEXT" |
||
| 55 | } |
||
| 56 | return "MEDIUMBLOB" |
||
| 57 | case fieldTypeNewDate: |
||
| 58 | return "DATE" |
||
| 59 | case fieldTypeNewDecimal: |
||
| 60 | return "DECIMAL" |
||
| 61 | case fieldTypeNULL: |
||
| 62 | return "NULL" |
||
| 63 | case fieldTypeSet: |
||
| 64 | return "SET" |
||
| 65 | case fieldTypeShort: |
||
| 66 | return "SMALLINT" |
||
| 67 | case fieldTypeString: |
||
| 68 | if mf.charSet == collations[binaryCollation] { |
||
| 69 | return "BINARY" |
||
| 70 | } |
||
| 71 | return "CHAR" |
||
| 72 | case fieldTypeTime: |
||
| 73 | return "TIME" |
||
| 74 | case fieldTypeTimestamp: |
||
| 75 | return "TIMESTAMP" |
||
| 76 | case fieldTypeTiny: |
||
| 77 | return "TINYINT" |
||
| 78 | case fieldTypeTinyBLOB: |
||
| 79 | if mf.charSet != collations[binaryCollation] { |
||
| 80 | return "TINYTEXT" |
||
| 81 | } |
||
| 82 | return "TINYBLOB" |
||
| 83 | case fieldTypeVarChar: |
||
| 84 | if mf.charSet == collations[binaryCollation] { |
||
| 85 | return "VARBINARY" |
||
| 86 | } |
||
| 87 | return "VARCHAR" |
||
| 88 | case fieldTypeVarString: |
||
| 89 | if mf.charSet == collations[binaryCollation] { |
||
| 90 | return "VARBINARY" |
||
| 91 | } |
||
| 92 | return "VARCHAR" |
||
| 93 | case fieldTypeYear: |
||
| 94 | return "YEAR" |
||
| 95 | default: |
||
| 96 | return "" |
||
| 97 | } |
||
| 195 |