Skip to content

Commit

Permalink
reduce cognitive complexity in ListContent functions
Browse files Browse the repository at this point in the history
Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Jul 25, 2023
1 parent 3f2bcd5 commit 31953ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 4 additions & 7 deletions pkg/controller/provider/web/openstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,14 @@ func (h *ProviderHandler) ListContent(ctx *gin.Context) (content []interface{},
ns := q.Get(base.NsParam)
for _, collector := range list {
if p, cast := collector.Owner().(*api.Provider); cast {
if p.Type() != api.OpenStack {
if p.Type() != api.OpenStack || (ns != "" && ns != p.Namespace) {
continue
}
if ns != "" && ns != p.Namespace {
continue
}
if collector, found := h.Container.Get(p); found {
h.Collector = collector
} else {
collector, found := h.Container.Get(p)
if !found {
continue
}
h.Collector = collector
m := &model.Provider{}
m.With(p)
r := Provider{}
Expand Down
11 changes: 4 additions & 7 deletions pkg/controller/provider/web/ova/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ func (h *ProviderHandler) ListContent(ctx *gin.Context) (content []interface{},
ns := q.Get(base.NsParam)
for _, collector := range list {
if p, cast := collector.Owner().(*api.Provider); cast {
if p.Type() != api.Ova {
if p.Type() != api.Ova || (ns != "" && ns != p.Namespace) {
continue
}
if ns != "" && ns != p.Namespace {
continue
}
if collector, found := h.Container.Get(p); found {
h.Collector = collector
} else {
collector, found := h.Container.Get(p)
if !found {
continue
}
h.Collector = collector
m := &model.Provider{}
m.With(p)
r := Provider{}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/provider/web/ovirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func (h *ProviderHandler) ListContent(ctx *gin.Context) (content []interface{},
if p.Type() != api.OVirt || (ns != "" && ns != p.Namespace) {
continue
}
if collector, found := h.Container.Get(p); found {
h.Collector = collector
} else {
collector, found := h.Container.Get(p)
if !found {
continue
}
h.Collector = collector
m := &model.Provider{}
m.With(p)
r := Provider{}
Expand Down

0 comments on commit 31953ef

Please sign in to comment.