Conditions | 28 |
Total Lines | 90 |
Code Lines | 59 |
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.NewHeadObjectResult 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 |
||
132 | func NewHeadObjectResult(output *SDK.HeadObjectResponse) *HeadObjectResult { |
||
133 | r := &HeadObjectResult{} |
||
134 | if output == nil { |
||
135 | return r |
||
136 | } |
||
137 | |||
138 | r.Exists = true |
||
139 | |||
140 | if output.AcceptRanges != nil { |
||
141 | r.AcceptRanges = *output.AcceptRanges |
||
142 | } |
||
143 | if output.CacheControl != nil { |
||
144 | r.CacheControl = *output.CacheControl |
||
145 | } |
||
146 | if output.ContentDisposition != nil { |
||
147 | r.ContentDisposition = *output.ContentDisposition |
||
148 | } |
||
149 | if output.ContentEncoding != nil { |
||
150 | r.ContentEncoding = *output.ContentEncoding |
||
151 | } |
||
152 | if output.ContentLanguage != nil { |
||
153 | r.ContentLanguage = *output.ContentLanguage |
||
154 | } |
||
155 | if output.ContentLength != nil { |
||
156 | r.ContentLength = *output.ContentLength |
||
157 | } |
||
158 | if output.ContentType != nil { |
||
159 | r.ContentType = *output.ContentType |
||
160 | } |
||
161 | if output.DeleteMarker != nil { |
||
162 | r.DeleteMarker = *output.DeleteMarker |
||
163 | } |
||
164 | if output.ETag != nil { |
||
165 | r.ETag = *output.ETag |
||
166 | } |
||
167 | if output.Expiration != nil { |
||
168 | r.Expiration = *output.Expiration |
||
169 | } |
||
170 | if output.Expires != nil { |
||
171 | r.Expires = *output.Expires |
||
172 | } |
||
173 | if output.LastModified != nil { |
||
174 | r.LastModified = *output.LastModified |
||
175 | } |
||
176 | |||
177 | r.Metadata = output.Metadata |
||
178 | |||
179 | if output.MissingMeta != nil { |
||
180 | r.MissingMeta = *output.MissingMeta |
||
181 | } |
||
182 | if r.ObjectLockLegalHoldStatus != "" { |
||
183 | r.ObjectLockLegalHoldStatus = ObjectLockLegalHoldStatus(output.ObjectLockLegalHoldStatus) |
||
184 | } |
||
185 | if r.ObjectLockMode != "" { |
||
186 | r.ObjectLockMode = ObjectLockMode(output.ObjectLockMode) |
||
187 | } |
||
188 | if output.PartsCount != nil { |
||
189 | r.PartsCount = *output.PartsCount |
||
190 | } |
||
191 | if r.ReplicationStatus != "" { |
||
192 | r.ReplicationStatus = ReplicationStatus(output.ReplicationStatus) |
||
193 | } |
||
194 | if r.RequestCharged != "" { |
||
195 | r.RequestCharged = RequestCharged(output.RequestCharged) |
||
196 | } |
||
197 | if output.Restore != nil { |
||
198 | r.Restore = *output.Restore |
||
199 | } |
||
200 | if output.SSECustomerAlgorithm != nil { |
||
201 | r.SSECustomerAlgorithm = *output.SSECustomerAlgorithm |
||
202 | } |
||
203 | if output.SSECustomerKeyMD5 != nil { |
||
204 | r.SSECustomerKeyMD5 = *output.SSECustomerKeyMD5 |
||
205 | } |
||
206 | if output.SSEKMSKeyId != nil { |
||
207 | r.SSEKMSKeyID = *output.SSEKMSKeyId |
||
208 | } |
||
209 | if r.ServerSideEncryption != "" { |
||
210 | r.ServerSideEncryption = ServerSideEncryption(output.ServerSideEncryption) |
||
211 | } |
||
212 | if r.StorageClass != "" { |
||
213 | r.StorageClass = StorageClass(output.StorageClass) |
||
214 | } |
||
215 | if output.VersionId != nil { |
||
216 | r.VersionID = *output.VersionId |
||
217 | } |
||
218 | if output.WebsiteRedirectLocation != nil { |
||
219 | r.WebsiteRedirectLocation = *output.WebsiteRedirectLocation |
||
220 | } |
||
221 | return r |
||
222 | } |
||
223 |