| Conditions | 13 |
| Total Lines | 58 |
| Code Lines | 36 |
| 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 dynamodb.ScanRequest.ToInput 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 | package dynamodb |
||
| 53 | func (r ScanRequest) ToInput() (*SDK.ScanInput, error) { |
||
| 54 | in := &SDK.ScanInput{} |
||
| 55 | |||
| 56 | if r.TableName != "" { |
||
| 57 | in.TableName = pointers.String(r.TableName) |
||
| 58 | } |
||
| 59 | |||
| 60 | if r.ConsistentRead { |
||
| 61 | in.ConsistentRead = pointers.Bool(r.ConsistentRead) |
||
| 62 | } |
||
| 63 | |||
| 64 | if len(r.ExclusiveStartKey) != 0 { |
||
| 65 | m := make(map[string]SDK.AttributeValue, len(r.ExclusiveStartKey)) |
||
| 66 | for key, val := range r.ExclusiveStartKey { |
||
| 67 | m[key] = val.ToSDK() |
||
| 68 | } |
||
| 69 | in.ExclusiveStartKey = m |
||
| 70 | } |
||
| 71 | |||
| 72 | in.ExpressionAttributeNames = r.ExpressionAttributeNames |
||
| 73 | |||
| 74 | if len(r.ExpressionAttributeValues) != 0 { |
||
| 75 | m := make(map[string]SDK.AttributeValue, len(r.ExpressionAttributeValues)) |
||
| 76 | for key, val := range r.ExpressionAttributeValues { |
||
| 77 | m[key] = val.ToSDK() |
||
| 78 | } |
||
| 79 | in.ExpressionAttributeValues = m |
||
| 80 | } |
||
| 81 | |||
| 82 | if r.FilterExpression != "" { |
||
| 83 | in.FilterExpression = pointers.String(r.FilterExpression) |
||
| 84 | } |
||
| 85 | if r.IndexName != "" { |
||
| 86 | in.IndexName = pointers.String(r.IndexName) |
||
| 87 | } |
||
| 88 | |||
| 89 | if r.Limit != 0 { |
||
| 90 | in.Limit = pointers.Long64(r.Limit) |
||
| 91 | } |
||
| 92 | if r.ProjectionExpression != "" { |
||
| 93 | in.ProjectionExpression = pointers.String(r.ProjectionExpression) |
||
| 94 | } |
||
| 95 | |||
| 96 | in.ReturnConsumedCapacity = SDK.ReturnConsumedCapacity(r.ReturnConsumedCapacity) |
||
| 97 | |||
| 98 | in.Select = SDK.Select(r.Select) |
||
| 99 | |||
| 100 | if r.XConditions.hasValue() { |
||
| 101 | expr, err := r.XConditions.Build() |
||
| 102 | if err != nil { |
||
| 103 | return nil, err |
||
| 104 | } |
||
| 105 | in.ExpressionAttributeNames = expr.Names() |
||
| 106 | in.ExpressionAttributeValues = expr.Values() |
||
| 107 | in.FilterExpression = expr.Filter() |
||
| 108 | in.ProjectionExpression = expr.Projection() |
||
| 109 | } |
||
| 110 | return in, nil |
||
| 111 | } |
||
| 152 |