| Conditions | 22 |
| Total Lines | 84 |
| Code Lines | 51 |
| 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.QueryRequest.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 |
||
| 54 | func (r QueryRequest) ToInput() (*SDK.QueryInput, error) { |
||
| 55 | in := &SDK.QueryInput{} |
||
| 56 | |||
| 57 | if r.TableName != "" { |
||
| 58 | in.TableName = pointers.String(r.TableName) |
||
| 59 | } |
||
| 60 | |||
| 61 | if r.ConsistentRead { |
||
| 62 | in.ConsistentRead = pointers.Bool(r.ConsistentRead) |
||
| 63 | } |
||
| 64 | |||
| 65 | if len(r.ExclusiveStartKey) != 0 { |
||
| 66 | m := make(map[string]SDK.AttributeValue, len(r.ExclusiveStartKey)) |
||
| 67 | for key, val := range r.ExclusiveStartKey { |
||
| 68 | m[key] = val.ToSDK() |
||
| 69 | } |
||
| 70 | in.ExclusiveStartKey = m |
||
| 71 | } |
||
| 72 | |||
| 73 | in.ExpressionAttributeNames = r.ExpressionAttributeNames |
||
| 74 | |||
| 75 | if len(r.ExpressionAttributeValues) != 0 { |
||
| 76 | m := make(map[string]SDK.AttributeValue, len(r.ExpressionAttributeValues)) |
||
| 77 | for key, val := range r.ExpressionAttributeValues { |
||
| 78 | m[key] = val.ToSDK() |
||
| 79 | } |
||
| 80 | in.ExpressionAttributeValues = m |
||
| 81 | } |
||
| 82 | |||
| 83 | if r.FilterExpression != "" { |
||
| 84 | in.FilterExpression = pointers.String(r.FilterExpression) |
||
| 85 | } |
||
| 86 | if r.IndexName != "" { |
||
| 87 | in.IndexName = pointers.String(r.IndexName) |
||
| 88 | } |
||
| 89 | if r.KeyConditionExpression != "" { |
||
| 90 | in.KeyConditionExpression = pointers.String(r.KeyConditionExpression) |
||
| 91 | } |
||
| 92 | |||
| 93 | if len(r.KeyConditions) != 0 { |
||
| 94 | m := make(map[string]SDK.Condition, len(r.KeyConditions)) |
||
| 95 | for key, val := range r.KeyConditions { |
||
| 96 | m[key] = val.ToSDK() |
||
| 97 | } |
||
| 98 | in.KeyConditions = m |
||
| 99 | } |
||
| 100 | |||
| 101 | if r.Limit != 0 { |
||
| 102 | in.Limit = pointers.Long64(r.Limit) |
||
| 103 | } |
||
| 104 | if r.ProjectionExpression != "" { |
||
| 105 | in.ProjectionExpression = pointers.String(r.ProjectionExpression) |
||
| 106 | } |
||
| 107 | |||
| 108 | in.ReturnConsumedCapacity = SDK.ReturnConsumedCapacity(r.ReturnConsumedCapacity) |
||
| 109 | |||
| 110 | if r.ScanIndexForward { |
||
| 111 | in.ScanIndexForward = pointers.Bool(r.ScanIndexForward) |
||
| 112 | } |
||
| 113 | |||
| 114 | in.Select = SDK.Select(r.Select) |
||
| 115 | |||
| 116 | if r.XConditions.hasValue() { |
||
| 117 | expr, err := r.XConditions.Build() |
||
| 118 | if err != nil { |
||
| 119 | return nil, err |
||
| 120 | } |
||
| 121 | if v := expr.Names(); v != nil { |
||
| 122 | in.ExpressionAttributeNames = v |
||
| 123 | } |
||
| 124 | if v := expr.Values(); v != nil { |
||
| 125 | in.ExpressionAttributeValues = v |
||
| 126 | } |
||
| 127 | if v := expr.Filter(); v != nil { |
||
| 128 | in.FilterExpression = v |
||
| 129 | } |
||
| 130 | if v := expr.KeyCondition(); v != nil { |
||
| 131 | in.KeyConditionExpression = v |
||
| 132 | } |
||
| 133 | if v := expr.Projection(); v != nil { |
||
| 134 | in.ProjectionExpression = v |
||
| 135 | } |
||
| 136 | } |
||
| 137 | return in, nil |
||
| 138 | } |
||
| 179 |