| Conditions | 28 | 
| Total Lines | 103 | 
| Code Lines | 67 | 
| 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 | ||
| 70 | func (r PutObjectRequest) ToInput() *SDK.PutObjectInput { | ||
| 71 | 	in := &SDK.PutObjectInput{} | ||
| 72 | 	if r.Bucket != "" { | ||
| 73 | in.Bucket = pointers.String(r.Bucket) | ||
| 74 | } | ||
| 75 | 	if r.Key != "" { | ||
| 76 | in.Key = pointers.String(r.Key) | ||
| 77 | } | ||
| 78 | |||
| 79 | in.ACL = SDK.ObjectCannedACL(r.ACL) | ||
| 80 | |||
| 81 | 	switch { | ||
| 82 | case r.Body != nil: | ||
| 83 | in.Body = r.Body | ||
| 84 | case len(r.BodyBytes) != 0: | ||
| 85 | in.Body = bytes.NewReader(r.BodyBytes) | ||
| 86 | } | ||
| 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.ContentLength != 0 { | ||
| 101 | in.ContentLength = pointers.Long64(r.ContentLength) | ||
| 102 | } | ||
| 103 | 	if r.ContentMD5 != "" { | ||
| 104 | in.ContentMD5 = pointers.String(r.ContentMD5) | ||
| 105 | } | ||
| 106 | 	if r.ContentType != "" { | ||
| 107 | in.ContentType = pointers.String(r.ContentType) | ||
| 108 | } | ||
| 109 | 	if !r.Expires.IsZero() { | ||
| 110 | in.Expires = &r.Expires | ||
| 111 | } | ||
| 112 | 	if r.GrantFullControl != "" { | ||
| 113 | in.GrantFullControl = pointers.String(r.GrantFullControl) | ||
| 114 | } | ||
| 115 | 	if r.GrantRead != "" { | ||
| 116 | in.GrantRead = pointers.String(r.GrantRead) | ||
| 117 | } | ||
| 118 | 	if r.GrantReadACP != "" { | ||
| 119 | in.GrantReadACP = pointers.String(r.GrantReadACP) | ||
| 120 | } | ||
| 121 | 	if r.GrantWriteACP != "" { | ||
| 122 | in.GrantWriteACP = pointers.String(r.GrantWriteACP) | ||
| 123 | } | ||
| 124 | |||
| 125 | in.Metadata = r.Metadata | ||
| 126 | in.ObjectLockLegalHoldStatus = SDK.ObjectLockLegalHoldStatus(r.ObjectLockLegalHoldStatus) | ||
| 127 | in.ObjectLockMode = SDK.ObjectLockMode(r.ObjectLockMode) | ||
| 128 | |||
| 129 | 	if !r.ObjectLockRetainUntilDate.IsZero() { | ||
| 130 | in.ObjectLockRetainUntilDate = &r.ObjectLockRetainUntilDate | ||
| 131 | } | ||
| 132 | |||
| 133 | in.RequestPayer = SDK.RequestPayer(r.RequestPayer) | ||
| 134 | |||
| 135 | 	if r.SSECustomerAlgorithm != "" { | ||
| 136 | in.SSECustomerAlgorithm = pointers.String(r.SSECustomerAlgorithm) | ||
| 137 | } | ||
| 138 | 	if r.SSECustomerKey != "" { | ||
| 139 | in.SSECustomerKey = pointers.String(r.SSECustomerKey) | ||
| 140 | } | ||
| 141 | 	if r.SSECustomerKeyMD5 != "" { | ||
| 142 | in.SSECustomerKeyMD5 = pointers.String(r.SSECustomerKeyMD5) | ||
| 143 | } | ||
| 144 | 	if r.SSEKMSEncryptionContext != "" { | ||
| 145 | in.SSEKMSEncryptionContext = pointers.String(r.SSEKMSEncryptionContext) | ||
| 146 | } | ||
| 147 | 	if r.SSEKMSKeyID != "" { | ||
| 148 | in.SSEKMSKeyId = pointers.String(r.SSEKMSKeyID) | ||
| 149 | } | ||
| 150 | |||
| 151 | in.ServerSideEncryption = SDK.ServerSideEncryption(r.ServerSideEncryption) | ||
| 152 | in.StorageClass = SDK.StorageClass(r.StorageClass) | ||
| 153 | |||
| 154 | tags := r.Tagging | ||
| 155 | 	if len(r.TaggingTagSet) != 0 { | ||
| 156 | tt := make([]string, 0, len(r.TaggingTagSet)) | ||
| 157 | 		if tags != "" { | ||
| 158 | tt = append(tt, tags) | ||
| 159 | } | ||
| 160 | 		for _, v := range r.TaggingTagSet { | ||
| 161 | tt = append(tt, v.Key+"="+v.Value) | ||
| 162 | } | ||
| 163 | tags = strings.Join(tt, "&") | ||
| 164 | } | ||
| 165 | 	if tags != "" { | ||
| 166 | in.Tagging = pointers.String(tags) | ||
| 167 | } | ||
| 168 | |||
| 169 | 	if r.WebsiteRedirectLocation != "" { | ||
| 170 | in.WebsiteRedirectLocation = pointers.String(r.WebsiteRedirectLocation) | ||
| 171 | } | ||
| 172 | return in | ||
| 173 | } | ||
| 223 |