Conditions | 19 |
Total Lines | 61 |
Code Lines | 40 |
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 s3.GetObjectRequest.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 s3 |
||
61 | func (r GetObjectRequest) ToInput() *SDK.GetObjectInput { |
||
62 | in := &SDK.GetObjectInput{} |
||
63 | if r.Bucket != "" { |
||
64 | in.Bucket = pointers.String(r.Bucket) |
||
65 | } |
||
66 | if r.Key != "" { |
||
67 | in.Key = pointers.String(r.Key) |
||
68 | } |
||
69 | |||
70 | if r.IfMatch != "" { |
||
71 | in.IfMatch = pointers.String(r.IfMatch) |
||
72 | } |
||
73 | if !r.IfModifiedSince.IsZero() { |
||
74 | in.IfModifiedSince = &r.IfModifiedSince |
||
75 | } |
||
76 | if r.IfNoneMatch != "" { |
||
77 | in.IfNoneMatch = pointers.String(r.IfNoneMatch) |
||
78 | } |
||
79 | if !r.IfUnmodifiedSince.IsZero() { |
||
80 | in.IfUnmodifiedSince = &r.IfUnmodifiedSince |
||
81 | } |
||
82 | if r.PartNumber != 0 { |
||
83 | in.PartNumber = pointers.Long64(r.PartNumber) |
||
84 | } |
||
85 | if r.Range != "" { |
||
86 | in.Range = pointers.String(r.Range) |
||
87 | } |
||
88 | |||
89 | in.RequestPayer = SDK.RequestPayer(r.RequestPayer) |
||
90 | |||
91 | if r.ResponseCacheControl != "" { |
||
92 | in.ResponseCacheControl = pointers.String(r.ResponseCacheControl) |
||
93 | } |
||
94 | if r.ResponseContentDisposition != "" { |
||
95 | in.ResponseContentDisposition = pointers.String(r.ResponseContentDisposition) |
||
96 | } |
||
97 | if r.ResponseContentEncoding != "" { |
||
98 | in.ResponseContentEncoding = pointers.String(r.ResponseContentEncoding) |
||
99 | } |
||
100 | if r.ResponseContentLanguage != "" { |
||
101 | in.ResponseContentLanguage = pointers.String(r.ResponseContentLanguage) |
||
102 | } |
||
103 | if r.ResponseContentType != "" { |
||
104 | in.ResponseContentType = pointers.String(r.ResponseContentType) |
||
105 | } |
||
106 | if !r.ResponseExpires.IsZero() { |
||
107 | in.ResponseExpires = &r.ResponseExpires |
||
108 | } |
||
109 | if r.SSECustomerAlgorithm != "" { |
||
110 | in.SSECustomerAlgorithm = pointers.String(r.SSECustomerAlgorithm) |
||
111 | } |
||
112 | if r.SSECustomerKey != "" { |
||
113 | in.SSECustomerKey = pointers.String(r.SSECustomerKey) |
||
114 | } |
||
115 | if r.SSECustomerKeyMD5 != "" { |
||
116 | in.SSECustomerKeyMD5 = pointers.String(r.SSECustomerKeyMD5) |
||
117 | } |
||
118 | if r.VersionID != "" { |
||
119 | in.VersionId = pointers.String(r.VersionID) |
||
120 | } |
||
121 | return in |
||
122 | } |
||
271 |