Conditions | 25 |
Total Lines | 91 |
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.PutObjectRequest.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 |
||
66 | func (r PutObjectRequest) ToInput() *SDK.PutObjectInput { |
||
67 | in := &SDK.PutObjectInput{} |
||
68 | if r.Bucket != "" { |
||
69 | in.Bucket = pointers.String(r.Bucket) |
||
70 | } |
||
71 | if r.Key != "" { |
||
72 | in.Key = pointers.String(r.Key) |
||
73 | } |
||
74 | |||
75 | in.ACL = SDK.ObjectCannedACL(r.ACL) |
||
76 | |||
77 | switch { |
||
78 | case r.Body != nil: |
||
79 | in.Body = r.Body |
||
80 | case len(r.BodyBytes) != 0: |
||
81 | in.Body = bytes.NewReader(r.BodyBytes) |
||
82 | } |
||
83 | |||
84 | if r.CacheControl != "" { |
||
85 | in.CacheControl = pointers.String(r.CacheControl) |
||
86 | } |
||
87 | if r.ContentDisposition != "" { |
||
88 | in.ContentDisposition = pointers.String(r.ContentDisposition) |
||
89 | } |
||
90 | if r.ContentEncoding != "" { |
||
91 | in.ContentEncoding = pointers.String(r.ContentEncoding) |
||
92 | } |
||
93 | if r.ContentLanguage != "" { |
||
94 | in.ContentLanguage = pointers.String(r.ContentLanguage) |
||
95 | } |
||
96 | if r.ContentLength != 0 { |
||
97 | in.ContentLength = pointers.Long64(r.ContentLength) |
||
98 | } |
||
99 | if r.ContentMD5 != "" { |
||
100 | in.ContentMD5 = pointers.String(r.ContentMD5) |
||
101 | } |
||
102 | if r.ContentType != "" { |
||
103 | in.ContentType = pointers.String(r.ContentType) |
||
104 | } |
||
105 | if !r.Expires.IsZero() { |
||
106 | in.Expires = &r.Expires |
||
107 | } |
||
108 | if r.GrantFullControl != "" { |
||
109 | in.GrantFullControl = pointers.String(r.GrantFullControl) |
||
110 | } |
||
111 | if r.GrantRead != "" { |
||
112 | in.GrantRead = pointers.String(r.GrantRead) |
||
113 | } |
||
114 | if r.GrantReadACP != "" { |
||
115 | in.GrantReadACP = pointers.String(r.GrantReadACP) |
||
116 | } |
||
117 | if r.GrantWriteACP != "" { |
||
118 | in.GrantWriteACP = pointers.String(r.GrantWriteACP) |
||
119 | } |
||
120 | |||
121 | in.Metadata = r.Metadata |
||
122 | in.ObjectLockLegalHoldStatus = SDK.ObjectLockLegalHoldStatus(r.ObjectLockLegalHoldStatus) |
||
123 | in.ObjectLockMode = SDK.ObjectLockMode(r.ObjectLockMode) |
||
124 | |||
125 | if !r.ObjectLockRetainUntilDate.IsZero() { |
||
126 | in.ObjectLockRetainUntilDate = &r.ObjectLockRetainUntilDate |
||
127 | } |
||
128 | |||
129 | in.RequestPayer = SDK.RequestPayer(r.RequestPayer) |
||
130 | |||
131 | if r.SSECustomerAlgorithm != "" { |
||
132 | in.SSECustomerAlgorithm = pointers.String(r.SSECustomerAlgorithm) |
||
133 | } |
||
134 | if r.SSECustomerKey != "" { |
||
135 | in.SSECustomerKey = pointers.String(r.SSECustomerKey) |
||
136 | } |
||
137 | if r.SSECustomerKeyMD5 != "" { |
||
138 | in.SSECustomerKeyMD5 = pointers.String(r.SSECustomerKeyMD5) |
||
139 | } |
||
140 | if r.SSEKMSEncryptionContext != "" { |
||
141 | in.SSEKMSEncryptionContext = pointers.String(r.SSEKMSEncryptionContext) |
||
142 | } |
||
143 | if r.SSEKMSKeyID != "" { |
||
144 | in.SSEKMSKeyId = pointers.String(r.SSEKMSKeyID) |
||
145 | } |
||
146 | |||
147 | in.ServerSideEncryption = SDK.ServerSideEncryption(r.ServerSideEncryption) |
||
148 | in.StorageClass = SDK.StorageClass(r.StorageClass) |
||
149 | |||
150 | if r.Tagging != "" { |
||
151 | in.Tagging = pointers.String(r.Tagging) |
||
152 | } |
||
153 | if r.WebsiteRedirectLocation != "" { |
||
154 | in.WebsiteRedirectLocation = pointers.String(r.WebsiteRedirectLocation) |
||
155 | } |
||
156 | return in |
||
157 | } |
||
207 |