| Conditions | 32 | 
| Total Lines | 117 | 
| Code Lines | 76 | 
| 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.CopyObjectRequest.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 | ||
| 74 | func (r CopyObjectRequest) ToInput() *SDK.CopyObjectInput { | ||
| 75 | 	in := &SDK.CopyObjectInput{} | ||
| 76 | 	if r.Bucket != "" { | ||
| 77 | in.Bucket = pointers.String(r.Bucket) | ||
| 78 | } | ||
| 79 | 	if r.Key != "" { | ||
| 80 | in.Key = pointers.String(r.Key) | ||
| 81 | } | ||
| 82 | 	if r.CopySource != "" { | ||
| 83 | in.CopySource = pointers.String(r.CopySource) | ||
| 84 | } | ||
| 85 | |||
| 86 | in.ACL = SDK.ObjectCannedACL(r.ACL) | ||
| 87 | |||
| 88 | 	if r.CacheControl != "" { | ||
| 89 | in.CacheControl = pointers.String(r.CacheControl) | ||
| 90 | } | ||
| 91 | 	if r.ContentDisposition != "" { | ||
| 92 | in.ContentDisposition = pointers.String(r.ContentDisposition) | ||
| 93 | } | ||
| 94 | 	if r.ContentEncoding != "" { | ||
| 95 | in.ContentEncoding = pointers.String(r.ContentEncoding) | ||
| 96 | } | ||
| 97 | 	if r.ContentLanguage != "" { | ||
| 98 | in.ContentLanguage = pointers.String(r.ContentLanguage) | ||
| 99 | } | ||
| 100 | 	if r.ContentType != "" { | ||
| 101 | in.ContentType = pointers.String(r.ContentType) | ||
| 102 | } | ||
| 103 | 	if r.CopySourceIfMatch != "" { | ||
| 104 | in.CopySourceIfMatch = pointers.String(r.CopySourceIfMatch) | ||
| 105 | } | ||
| 106 | 	if !r.CopySourceIfModifiedSince.IsZero() { | ||
| 107 | in.CopySourceIfModifiedSince = &r.CopySourceIfModifiedSince | ||
| 108 | } | ||
| 109 | 	if r.CopySourceIfNoneMatch != "" { | ||
| 110 | in.CopySourceIfNoneMatch = pointers.String(r.CopySourceIfNoneMatch) | ||
| 111 | } | ||
| 112 | 	if !r.CopySourceIfUnmodifiedSince.IsZero() { | ||
| 113 | in.CopySourceIfUnmodifiedSince = &r.CopySourceIfUnmodifiedSince | ||
| 114 | } | ||
| 115 | 	if r.CopySourceSSECustomerAlgorithm != "" { | ||
| 116 | in.CopySourceSSECustomerAlgorithm = pointers.String(r.CopySourceSSECustomerAlgorithm) | ||
| 117 | } | ||
| 118 | 	if r.CopySourceSSECustomerKey != "" { | ||
| 119 | in.CopySourceSSECustomerKey = pointers.String(r.CopySourceSSECustomerKey) | ||
| 120 | } | ||
| 121 | 	if r.CopySourceSSECustomerKeyMD5 != "" { | ||
| 122 | in.CopySourceSSECustomerKeyMD5 = pointers.String(r.CopySourceSSECustomerKeyMD5) | ||
| 123 | } | ||
| 124 | 	if !r.Expires.IsZero() { | ||
| 125 | in.Expires = &r.Expires | ||
| 126 | } | ||
| 127 | 	if r.GrantFullControl != "" { | ||
| 128 | in.GrantFullControl = pointers.String(r.GrantFullControl) | ||
| 129 | } | ||
| 130 | 	if r.GrantRead != "" { | ||
| 131 | in.GrantRead = pointers.String(r.GrantRead) | ||
| 132 | } | ||
| 133 | 	if r.GrantReadACP != "" { | ||
| 134 | in.GrantReadACP = pointers.String(r.GrantReadACP) | ||
| 135 | } | ||
| 136 | 	if r.GrantWriteACP != "" { | ||
| 137 | in.GrantWriteACP = pointers.String(r.GrantWriteACP) | ||
| 138 | } | ||
| 139 | |||
| 140 | in.Metadata = r.Metadata | ||
| 141 | in.MetadataDirective = SDK.MetadataDirective(r.MetadataDirective) | ||
| 142 | in.ObjectLockLegalHoldStatus = SDK.ObjectLockLegalHoldStatus(r.ObjectLockLegalHoldStatus) | ||
| 143 | in.ObjectLockMode = SDK.ObjectLockMode(r.ObjectLockMode) | ||
| 144 | |||
| 145 | 	if !r.ObjectLockRetainUntilDate.IsZero() { | ||
| 146 | in.ObjectLockRetainUntilDate = &r.ObjectLockRetainUntilDate | ||
| 147 | } | ||
| 148 | |||
| 149 | in.RequestPayer = SDK.RequestPayer(r.RequestPayer) | ||
| 150 | |||
| 151 | 	if r.SSECustomerAlgorithm != "" { | ||
| 152 | in.SSECustomerAlgorithm = pointers.String(r.SSECustomerAlgorithm) | ||
| 153 | } | ||
| 154 | 	if r.SSECustomerKey != "" { | ||
| 155 | in.SSECustomerKey = pointers.String(r.SSECustomerKey) | ||
| 156 | } | ||
| 157 | 	if r.SSECustomerKeyMD5 != "" { | ||
| 158 | in.SSECustomerKeyMD5 = pointers.String(r.SSECustomerKeyMD5) | ||
| 159 | } | ||
| 160 | 	if r.SSEKMSEncryptionContext != "" { | ||
| 161 | in.SSEKMSEncryptionContext = pointers.String(r.SSEKMSEncryptionContext) | ||
| 162 | } | ||
| 163 | 	if r.SSEKMSKeyID != "" { | ||
| 164 | in.SSEKMSKeyId = pointers.String(r.SSEKMSKeyID) | ||
| 165 | } | ||
| 166 | |||
| 167 | in.ServerSideEncryption = SDK.ServerSideEncryption(r.ServerSideEncryption) | ||
| 168 | in.StorageClass = SDK.StorageClass(r.StorageClass) | ||
| 169 | |||
| 170 | tags := r.Tagging | ||
| 171 | 	if len(r.TaggingTagSet) != 0 { | ||
| 172 | tt := make([]string, 0, len(r.TaggingTagSet)) | ||
| 173 | 		if tags != "" { | ||
| 174 | tt = append(tt, tags) | ||
| 175 | } | ||
| 176 | 		for _, v := range r.TaggingTagSet { | ||
| 177 | tt = append(tt, v.Key+"="+v.Value) | ||
| 178 | } | ||
| 179 | tags = strings.Join(tt, "&") | ||
| 180 | } | ||
| 181 | 	if tags != "" { | ||
| 182 | in.Tagging = pointers.String(tags) | ||
| 183 | } | ||
| 184 | |||
| 185 | in.TaggingDirective = SDK.TaggingDirective(r.TaggingDirective) | ||
| 186 | |||
| 187 | 	if r.WebsiteRedirectLocation != "" { | ||
| 188 | in.WebsiteRedirectLocation = pointers.String(r.WebsiteRedirectLocation) | ||
| 189 | } | ||
| 190 | return in | ||
| 191 | } | ||
| 254 |