Passed
Push — master ( 44e67e...3437b8 )
by eval
01:37
created

ssm.newParameterHistory   C

Complexity

Conditions 11

Size

Total Lines 39
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 27
nop 1
dl 0
loc 39
rs 5.4
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like ssm.newParameterHistory 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 ssm
2
3
import (
4
	"time"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/ssm"
7
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
8
)
9
10
type Parameter struct {
0 ignored issues
show
introduced by
exported type Parameter should have comment or be unexported
Loading history...
11
	ARN              string
12
	DataType         string
13
	LastModifiedDate time.Time
14
	Name             string
15
	Selector         string
16
	SourceResult     string
17
	Type             ParameterType
18
	Value            string
19
	Version          int64
20
}
21
22
func newParameter(o *SDK.Parameter) Parameter {
23
	result := Parameter{}
24
	if o == nil {
25
		return result
26
	}
27
28
	if o.ARN != nil {
29
		result.ARN = *o.ARN
30
	}
31
	if o.DataType != nil {
32
		result.DataType = *o.DataType
33
	}
34
	if o.LastModifiedDate != nil {
35
		result.LastModifiedDate = *o.LastModifiedDate
36
	}
37
	if o.Name != nil {
38
		result.Name = *o.Name
39
	}
40
	if o.Selector != nil {
41
		result.Selector = *o.Selector
42
	}
43
	if o.SourceResult != nil {
44
		result.SourceResult = *o.SourceResult
45
	}
46
	result.Type = ParameterType(o.Type)
47
	if o.Value != nil {
48
		result.Value = *o.Value
49
	}
50
	if o.Version != nil {
51
		result.Version = *o.Version
52
	}
53
	return result
54
}
55
56
type ParameterHistory struct {
0 ignored issues
show
introduced by
exported type ParameterHistory should have comment or be unexported
Loading history...
57
	AllowedPattern   string
58
	DataType         string
59
	Description      string
60
	KeyID            string
61
	Labels           []string
62
	LastModifiedDate time.Time
63
	LastModifiedUser string
64
	Name             string
65
	Policies         []ParameterInlinePolicy
66
	Tier             ParameterTier
67
	Type             ParameterType
68
	Value            string
69
	Version          int64
70
}
71
72
func newParameterHistory(o *SDK.ParameterHistory) ParameterHistory {
73
	result := ParameterHistory{}
74
	if o == nil {
75
		return result
76
	}
77
78
	if o.AllowedPattern != nil {
79
		result.AllowedPattern = *o.AllowedPattern
80
	}
81
	if o.DataType != nil {
82
		result.DataType = *o.DataType
83
	}
84
	if o.Description != nil {
85
		result.Description = *o.Description
86
	}
87
	if o.KeyId != nil {
88
		result.KeyID = *o.KeyId
89
	}
90
	if o.LastModifiedDate != nil {
91
		result.LastModifiedDate = *o.LastModifiedDate
92
	}
93
	if o.LastModifiedUser != nil {
94
		result.LastModifiedUser = *o.LastModifiedUser
95
	}
96
	if o.Name != nil {
97
		result.Name = *o.Name
98
	}
99
	if o.Value != nil {
100
		result.Value = *o.Value
101
	}
102
	if o.Version != nil {
103
		result.Version = *o.Version
104
	}
105
106
	result.Labels = o.Labels
107
	result.Policies = newParameterInlinePolicyList(o.Policies)
108
	result.Tier = ParameterTier(o.Tier)
109
	result.Type = ParameterType(o.Type)
110
	return result
111
}
112
113
type ParameterInlinePolicy struct {
0 ignored issues
show
introduced by
exported type ParameterInlinePolicy should have comment or be unexported
Loading history...
114
	PolicyStatus string
115
	PolicyText   string
116
	PolicyType   string
117
}
118
119
func newParameterInlinePolicyList(list []SDK.ParameterInlinePolicy) []ParameterInlinePolicy {
120
	if len(list) == 0 {
121
		return nil
122
	}
123
124
	results := make([]ParameterInlinePolicy, len(list))
125
	for i := range list {
126
		results[i] = newParameterInlinePolicy(&list[i])
127
	}
128
	return results
129
}
130
131
func newParameterInlinePolicy(o *SDK.ParameterInlinePolicy) ParameterInlinePolicy {
132
	result := ParameterInlinePolicy{}
133
	if o == nil {
134
		return result
135
	}
136
137
	if o.PolicyStatus != nil {
138
		result.PolicyStatus = *o.PolicyStatus
139
	}
140
	if o.PolicyText != nil {
141
		result.PolicyText = *o.PolicyText
142
	}
143
	if o.PolicyType != nil {
144
		result.PolicyType = *o.PolicyType
145
	}
146
	return result
147
}
148
149
type ParameterMetadata struct {
0 ignored issues
show
introduced by
exported type ParameterMetadata should have comment or be unexported
Loading history...
150
	AllowedPattern   string
151
	DataType         string
152
	Description      string
153
	KeyID            string
154
	LastModifiedDate time.Time
155
	LastModifiedUser string
156
	Name             string
157
	Policies         []ParameterInlinePolicy
158
	Tier             ParameterTier
159
	Type             ParameterType
160
	Version          int64
161
}
162
163
func newParameterMetadata(o SDK.ParameterMetadata) ParameterMetadata {
164
	result := ParameterMetadata{}
165
166
	if o.AllowedPattern != nil {
167
		result.AllowedPattern = *o.AllowedPattern
168
	}
169
	if o.DataType != nil {
170
		result.DataType = *o.DataType
171
	}
172
	if o.Description != nil {
173
		result.Description = *o.Description
174
	}
175
	if o.KeyId != nil {
176
		result.KeyID = *o.KeyId
177
	}
178
	if o.LastModifiedDate != nil {
179
		result.LastModifiedDate = *o.LastModifiedDate
180
	}
181
	if o.LastModifiedUser != nil {
182
		result.LastModifiedUser = *o.LastModifiedUser
183
	}
184
	if o.Name != nil {
185
		result.Name = *o.Name
186
	}
187
	if o.Version != nil {
188
		result.Version = *o.Version
189
	}
190
191
	result.Policies = newParameterInlinePolicyList(o.Policies)
192
	result.Tier = ParameterTier(o.Tier)
193
	result.Type = ParameterType(o.Type)
194
	return result
195
}
196
197
type ParameterStringFilter struct {
0 ignored issues
show
introduced by
exported type ParameterStringFilter should have comment or be unexported
Loading history...
198
	Key    string
199
	Option string
200
	Values []string
201
}
202
203
func (v ParameterStringFilter) ToSDK() SDK.ParameterStringFilter {
0 ignored issues
show
introduced by
exported method ParameterStringFilter.ToSDK should have comment or be unexported
Loading history...
204
	o := SDK.ParameterStringFilter{}
205
	if v.Key != "" {
206
		o.Key = pointers.String(v.Key)
207
	}
208
	if v.Option != "" {
209
		o.Option = pointers.String(v.Option)
210
	}
211
	o.Values = v.Values
212
	return o
213
}
214
215
type Tag struct {
0 ignored issues
show
introduced by
exported type Tag should have comment or be unexported
Loading history...
216
	Key   string
217
	Value string
218
}
219
220
func (r Tag) ToSDK() SDK.Tag {
0 ignored issues
show
introduced by
exported method Tag.ToSDK should have comment or be unexported
Loading history...
221
	o := SDK.Tag{}
222
223
	if r.Key != "" {
224
		o.Key = pointers.String(r.Key)
225
	}
226
	if r.Value != "" {
227
		o.Value = pointers.String(r.Value)
228
	}
229
	return o
230
}
231