| Conditions | 20 |
| Total Lines | 88 |
| 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 pinpointemail.SendEmailRequest.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 pinpointemail |
||
| 54 | func (r SendEmailRequest) ToInput() *SDK.SendEmailInput { |
||
| 55 | in := &SDK.SendEmailInput{} |
||
| 56 | switch { |
||
| 57 | case len(r.To) != 0, |
||
| 58 | len(r.Cc) != 0, |
||
| 59 | len(r.Bcc) != 0: |
||
| 60 | in.Destination = &SDK.Destination{ |
||
| 61 | ToAddresses: r.To, |
||
| 62 | CcAddresses: r.Cc, |
||
| 63 | BccAddresses: r.Bcc, |
||
| 64 | } |
||
| 65 | } |
||
| 66 | if r.From != "" { |
||
| 67 | in.FromEmailAddress = pointers.String(r.From) |
||
| 68 | } |
||
| 69 | |||
| 70 | if len(r.RawMessageData) != 0 { |
||
| 71 | in.Content = &SDK.EmailContent{ |
||
| 72 | Raw: &SDK.RawMessage{ |
||
| 73 | Data: r.RawMessageData, |
||
| 74 | }, |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | switch { |
||
| 79 | case r.Subject != "", |
||
| 80 | r.HTMLBody != "": |
||
| 81 | if in.Content == nil { |
||
| 82 | in.Content = &SDK.EmailContent{} |
||
| 83 | } |
||
| 84 | in.Content.Simple = &SDK.Message{} |
||
| 85 | } |
||
| 86 | |||
| 87 | if r.Subject != "" { |
||
| 88 | content := SDK.Content{ |
||
| 89 | Data: pointers.String(r.Subject), |
||
| 90 | } |
||
| 91 | if r.SubjectCharset != "" { |
||
| 92 | content.Charset = pointers.String(r.SubjectCharset) |
||
| 93 | } |
||
| 94 | in.Content.Simple.Subject = &content |
||
| 95 | } |
||
| 96 | |||
| 97 | if r.HTMLBody != "" || r.TextBody != "" { |
||
| 98 | body := SDK.Body{} |
||
| 99 | if r.HTMLBody != "" { |
||
| 100 | content := SDK.Content{} |
||
| 101 | content.Data = pointers.String(r.HTMLBody) |
||
| 102 | if r.HTMLCharset != "" { |
||
| 103 | content.Charset = pointers.String(r.HTMLCharset) |
||
| 104 | } |
||
| 105 | body.Html = &content |
||
| 106 | } |
||
| 107 | if r.TextBody != "" { |
||
| 108 | content := SDK.Content{} |
||
| 109 | content.Data = pointers.String(r.TextBody) |
||
| 110 | if r.TextCharset != "" { |
||
| 111 | content.Charset = pointers.String(r.TextCharset) |
||
| 112 | } |
||
| 113 | body.Text = &content |
||
| 114 | } |
||
| 115 | in.Content.Simple.Body = &body |
||
| 116 | } |
||
| 117 | |||
| 118 | if r.TemplateARN != "" { |
||
| 119 | template := SDK.Template{ |
||
| 120 | TemplateArn: pointers.String(r.TemplateARN), |
||
| 121 | } |
||
| 122 | if r.TemplateData != "" { |
||
| 123 | template.TemplateData = pointers.String(r.TemplateData) |
||
| 124 | } |
||
| 125 | in.Content.Template = &template |
||
| 126 | } |
||
| 127 | |||
| 128 | if r.ConfigurationSetName != "" { |
||
| 129 | in.ConfigurationSetName = pointers.String(r.ConfigurationSetName) |
||
| 130 | } |
||
| 131 | if len(r.EmailTags) != 0 { |
||
| 132 | list := make([]SDK.MessageTag, len(r.EmailTags)) |
||
| 133 | for i, v := range r.EmailTags { |
||
| 134 | list[i] = v.ToEmailTag() |
||
| 135 | } |
||
| 136 | } |
||
| 137 | if r.FeedbackForwardingEmailAddress != "" { |
||
| 138 | in.FeedbackForwardingEmailAddress = pointers.String(r.FeedbackForwardingEmailAddress) |
||
| 139 | } |
||
| 140 | in.ReplyToAddresses = r.ReplyToAddresses |
||
| 141 | return in |
||
| 142 | } |
||
| 159 |