Conditions | 16 |
Total Lines | 66 |
Code Lines | 42 |
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 ses.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 ses |
||
49 | func (r SendEmailRequest) ToInput() *SDK.SendEmailInput { |
||
50 | in := &SDK.SendEmailInput{ |
||
51 | Message: &SDK.Message{}, |
||
52 | } |
||
53 | |||
54 | in.Destination = r.Destination.ToSDK() |
||
55 | |||
56 | if r.Source != "" { |
||
57 | in.Source = pointers.String(r.Source) |
||
58 | } |
||
59 | |||
60 | if r.Subject != "" { |
||
61 | content := SDK.Content{ |
||
62 | Data: pointers.String(r.Subject), |
||
63 | } |
||
64 | if r.SubjectCharset != "" { |
||
65 | content.Charset = pointers.String(r.SubjectCharset) |
||
66 | } |
||
67 | in.Message.Subject = &content |
||
68 | } |
||
69 | |||
70 | if r.HTMLBody != "" || r.TextBody != "" { |
||
71 | body := SDK.Body{} |
||
72 | if r.HTMLBody != "" { |
||
73 | content := SDK.Content{} |
||
74 | content.Data = pointers.String(r.HTMLBody) |
||
75 | if r.HTMLCharset != "" { |
||
76 | content.Charset = pointers.String(r.HTMLCharset) |
||
77 | } |
||
78 | body.Html = &content |
||
79 | } |
||
80 | if r.TextBody != "" { |
||
81 | content := SDK.Content{} |
||
82 | content.Data = pointers.String(r.TextBody) |
||
83 | if r.TextCharset != "" { |
||
84 | content.Charset = pointers.String(r.TextCharset) |
||
85 | } |
||
86 | body.Text = &content |
||
87 | } |
||
88 | in.Message.Body = &body |
||
89 | } |
||
90 | |||
91 | if r.ConfigurationSetName != "" { |
||
92 | in.ConfigurationSetName = pointers.String(r.ConfigurationSetName) |
||
93 | } |
||
94 | |||
95 | in.ReplyToAddresses = r.ReplyToAddresses |
||
96 | |||
97 | if r.ReturnPath != "" { |
||
98 | in.ReturnPath = pointers.String(r.ReturnPath) |
||
99 | } |
||
100 | if r.ReturnPathARN != "" { |
||
101 | in.ReturnPathArn = pointers.String(r.ReturnPathARN) |
||
102 | } |
||
103 | if r.SourceARN != "" { |
||
104 | in.SourceArn = pointers.String(r.SourceARN) |
||
105 | } |
||
106 | |||
107 | if len(r.Tags) != 0 { |
||
108 | list := make([]SDK.MessageTag, len(r.Tags)) |
||
109 | for i, v := range r.Tags { |
||
110 | list[i] = v.ToSDK() |
||
111 | } |
||
112 | in.Tags = list |
||
113 | } |
||
114 | return in |
||
115 | } |
||
132 |