Passed
Pull Request — master (#29)
by eval
02:10
created

pinpoint.newImportJobResponse   D

Complexity

Conditions 12

Size

Total Lines 47
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 28
nop 1
dl 0
loc 47
rs 4.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like pinpoint.newImportJobResponse 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 pinpoint
2
3
import (
4
	SDK "github.com/aws/aws-sdk-go-v2/service/pinpoint"
5
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
6
)
7
8
type ImportJobRequest struct {
0 ignored issues
show
introduced by
exported type ImportJobRequest should have comment or be unexported
Loading history...
9
	Format  Format
10
	RoleARN string
11
	S3URL   string
12
13
	// optional
14
	DefineSegment     bool
15
	RegisterEndpoints bool
16
	SegmentID         string
17
	SegmentName       string
18
}
19
20
func (r ImportJobRequest) ToSDK() *SDK.ImportJobRequest {
0 ignored issues
show
introduced by
exported method ImportJobRequest.ToSDK should have comment or be unexported
Loading history...
21
	o := SDK.ImportJobRequest{}
22
23
	o.Format = SDK.Format(r.Format)
24
25
	if r.RoleARN != "" {
26
		o.RoleArn = pointers.String(r.RoleARN)
27
	}
28
	if r.S3URL != "" {
29
		o.S3Url = pointers.String(r.S3URL)
30
	}
31
32
	if r.DefineSegment {
33
		o.DefineSegment = pointers.Bool(r.DefineSegment)
34
	}
35
	if r.RegisterEndpoints {
36
		o.RegisterEndpoints = pointers.Bool(r.RegisterEndpoints)
37
	}
38
	if r.SegmentID != "" {
39
		o.SegmentId = pointers.String(r.SegmentID)
40
	}
41
	if r.SegmentName != "" {
42
		o.SegmentName = pointers.String(r.SegmentName)
43
	}
44
	return &o
45
}
46
47
type ImportJobsResponse struct {
0 ignored issues
show
introduced by
exported type ImportJobsResponse should have comment or be unexported
Loading history...
48
	Item      []ImportJobResponse
49
	NextToken string
50
}
51
52
func newImportJobsResponse(o *SDK.ImportJobsResponse) ImportJobsResponse {
53
	result := ImportJobsResponse{}
54
	if o == nil {
55
		return result
56
	}
57
58
	if len(o.Item) != 0 {
59
		list := make([]ImportJobResponse, len(o.Item))
60
		for i, v := range o.Item {
61
			list[i] = newImportJobResponse(&v)
62
		}
63
		result.Item = list
64
	}
65
66
	if o.NextToken != nil {
67
		result.NextToken = *o.NextToken
68
	}
69
70
	return result
71
}
72
73
type ImportJobResponse struct {
0 ignored issues
show
introduced by
exported type ImportJobResponse should have comment or be unexported
Loading history...
74
	ApplicationID string
75
	CreationDate  string
76
	Definition    ImportJobResource
77
	ID            string
78
	JobStatus     JobStatus
79
	Type          string
80
81
	// optional
82
	CompletedPieces int64
83
	CompletionDate  string
84
	FailedPieces    int64
85
	Failures        []string
86
	TotalFailures   int64
87
	TotalPieces     int64
88
	TotalProcessed  int64
89
}
90
91
func newImportJobResponse(o *SDK.ImportJobResponse) ImportJobResponse {
92
	result := ImportJobResponse{}
93
	if o == nil {
94
		return result
95
	}
96
97
	if o.ApplicationId != nil {
98
		result.ApplicationID = *o.ApplicationId
99
	}
100
	if o.CreationDate != nil {
101
		result.CreationDate = *o.CreationDate
102
	}
103
104
	result.Definition = newImportJobResource(o.Definition)
105
106
	if o.Id != nil {
107
		result.ID = *o.Id
108
	}
109
110
	result.JobStatus = JobStatus(o.JobStatus)
111
112
	if o.Type != nil {
113
		result.Type = *o.Type
114
	}
115
116
	if o.CompletedPieces != nil {
117
		result.CompletedPieces = *o.CompletedPieces
118
	}
119
	if o.CompletionDate != nil {
120
		result.CompletionDate = *o.CompletionDate
121
	}
122
	if o.FailedPieces != nil {
123
		result.FailedPieces = *o.FailedPieces
124
	}
125
126
	result.Failures = o.Failures
127
128
	if o.TotalFailures != nil {
129
		result.TotalFailures = *o.TotalFailures
130
	}
131
	if o.TotalPieces != nil {
132
		result.TotalPieces = *o.TotalPieces
133
	}
134
	if o.TotalProcessed != nil {
135
		result.TotalProcessed = *o.TotalProcessed
136
	}
137
	return result
138
}
139
140
type ImportJobResource struct {
0 ignored issues
show
introduced by
exported type ImportJobResource should have comment or be unexported
Loading history...
141
	Format  Format
142
	RoleARN string
143
	S3URL   string
144
145
	// optional
146
	DefineSegment     bool
147
	ExternalID        string
148
	RegisterEndpoints bool
149
	SegmentID         string
150
	SegmentName       string
151
}
152
153
func newImportJobResource(o *SDK.ImportJobResource) ImportJobResource {
154
	result := ImportJobResource{}
155
	if o == nil {
156
		return result
157
	}
158
159
	result.Format = Format(o.Format)
160
161
	if o.RoleArn != nil {
162
		result.RoleARN = *o.RoleArn
163
	}
164
	if o.S3Url != nil {
165
		result.S3URL = *o.S3Url
166
	}
167
168
	if o.DefineSegment != nil {
169
		result.DefineSegment = *o.DefineSegment
170
	}
171
	if o.ExternalId != nil {
172
		result.ExternalID = *o.ExternalId
173
	}
174
	if o.RegisterEndpoints != nil {
175
		result.RegisterEndpoints = *o.RegisterEndpoints
176
	}
177
	if o.SegmentId != nil {
178
		result.SegmentID = *o.SegmentId
179
	}
180
	if o.SegmentName != nil {
181
		result.SegmentName = *o.SegmentName
182
	}
183
	return result
184
}
185