Conditions | 31 |
Total Lines | 99 |
Code Lines | 65 |
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.NewGetObjectResult 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 |
||
161 | func NewGetObjectResult(output *SDK.GetObjectResponse) *GetObjectResult { |
||
162 | r := &GetObjectResult{} |
||
163 | if output == nil { |
||
164 | return r |
||
165 | } |
||
166 | |||
167 | r.Exists = true |
||
168 | |||
169 | if output.AcceptRanges != nil { |
||
170 | r.AcceptRanges = *output.AcceptRanges |
||
171 | } |
||
172 | if output.Body != nil { |
||
173 | r.Body = output.Body |
||
174 | } |
||
175 | if output.CacheControl != nil { |
||
176 | r.CacheControl = *output.CacheControl |
||
177 | } |
||
178 | if output.ContentDisposition != nil { |
||
179 | r.ContentDisposition = *output.ContentDisposition |
||
180 | } |
||
181 | if output.ContentEncoding != nil { |
||
182 | r.ContentEncoding = *output.ContentEncoding |
||
183 | } |
||
184 | if output.ContentLanguage != nil { |
||
185 | r.ContentLanguage = *output.ContentLanguage |
||
186 | } |
||
187 | if output.ContentLength != nil { |
||
188 | r.ContentLength = *output.ContentLength |
||
189 | } |
||
190 | if output.ContentRange != nil { |
||
191 | r.ContentRange = *output.ContentRange |
||
192 | } |
||
193 | if output.ContentType != nil { |
||
194 | r.ContentType = *output.ContentType |
||
195 | } |
||
196 | if output.DeleteMarker != nil { |
||
197 | r.DeleteMarker = *output.DeleteMarker |
||
198 | } |
||
199 | if output.ETag != nil { |
||
200 | r.ETag = *output.ETag |
||
201 | } |
||
202 | if output.Expiration != nil { |
||
203 | r.Expiration = *output.Expiration |
||
204 | } |
||
205 | if output.Expires != nil { |
||
206 | r.Expires = *output.Expires |
||
207 | } |
||
208 | if output.LastModified != nil { |
||
209 | r.LastModified = *output.LastModified |
||
210 | } |
||
211 | |||
212 | r.Metadata = output.Metadata |
||
213 | |||
214 | if output.MissingMeta != nil { |
||
215 | r.MissingMeta = *output.MissingMeta |
||
216 | } |
||
217 | if r.ObjectLockLegalHoldStatus != "" { |
||
218 | r.ObjectLockLegalHoldStatus = ObjectLockLegalHoldStatus(output.ObjectLockLegalHoldStatus) |
||
219 | } |
||
220 | if r.ObjectLockMode != "" { |
||
221 | r.ObjectLockMode = ObjectLockMode(output.ObjectLockMode) |
||
222 | } |
||
223 | if output.PartsCount != nil { |
||
224 | r.PartsCount = *output.PartsCount |
||
225 | } |
||
226 | if r.ReplicationStatus != "" { |
||
227 | r.ReplicationStatus = ReplicationStatus(output.ReplicationStatus) |
||
228 | } |
||
229 | if r.RequestCharged != "" { |
||
230 | r.RequestCharged = RequestCharged(output.RequestCharged) |
||
231 | } |
||
232 | if output.Restore != nil { |
||
233 | r.Restore = *output.Restore |
||
234 | } |
||
235 | if output.SSECustomerAlgorithm != nil { |
||
236 | r.SSECustomerAlgorithm = *output.SSECustomerAlgorithm |
||
237 | } |
||
238 | if output.SSECustomerKeyMD5 != nil { |
||
239 | r.SSECustomerKeyMD5 = *output.SSECustomerKeyMD5 |
||
240 | } |
||
241 | if output.SSEKMSKeyId != nil { |
||
242 | r.SSEKMSKeyID = *output.SSEKMSKeyId |
||
243 | } |
||
244 | if r.ServerSideEncryption != "" { |
||
245 | r.ServerSideEncryption = ServerSideEncryption(output.ServerSideEncryption) |
||
246 | } |
||
247 | if r.StorageClass != "" { |
||
248 | r.StorageClass = StorageClass(output.StorageClass) |
||
249 | } |
||
250 | if output.TagCount != nil { |
||
251 | r.TagCount = *output.TagCount |
||
252 | } |
||
253 | if output.VersionId != nil { |
||
254 | r.VersionID = *output.VersionId |
||
255 | } |
||
256 | if output.WebsiteRedirectLocation != nil { |
||
257 | r.WebsiteRedirectLocation = *output.WebsiteRedirectLocation |
||
258 | } |
||
259 | return r |
||
260 | } |
||
271 |