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