horizoncd/horizon

View on GitHub
core/controller/group/controller.go

Summary

Maintainability
D
2 days
Test Coverage
C
77%

Showing 12 of 12 total issues

Method controller.GetByFullPath has a Cognitive Complexity of 60 (exceeds 20 allowed). Consider refactoring.
Open

func (c *controller) GetByFullPath(ctx context.Context,
resourcePath string, resourceType string) (*service.Child, error) {
const op = "get record by fullPath"
defer wlog.Start(ctx, op).StopPrint()
 
 
Severity: Minor
Found in core/controller/group/controller.go - About 6 hrs to fix

Method controller.GetByFullPath has 124 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (c *controller) GetByFullPath(ctx context.Context,
resourcePath string, resourceType string) (*service.Child, error) {
const op = "get record by fullPath"
defer wlog.Start(ctx, op).StopPrint()
 
 
Severity: Major
Found in core/controller/group/controller.go - About 3 hrs to fix

    File controller.go has 535 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    // Copyright © 2023 Horizoncd.
    //
    // Licensed under the Apache License, Version 2.0 (the "License");
    // you may not use this file except in compliance with the License.
    // You may obtain a copy of the License at
    Severity: Minor
    Found in core/controller/group/controller.go - About 2 hrs to fix

      Method controller.GetByFullPath has 24 return statements (exceeds 4 allowed).
      Open

      func (c *controller) GetByFullPath(ctx context.Context,
      resourcePath string, resourceType string) (*service.Child, error) {
      const op = "get record by fullPath"
      defer wlog.Start(ctx, op).StopPrint()
       
       
      Severity: Major
      Found in core/controller/group/controller.go - About 2 hrs to fix

        Method controller.SearchChildren has 7 return statements (exceeds 4 allowed).
        Open

        func (c *controller) SearchChildren(ctx context.Context, params *SearchParams) ([]*service.Child, int64, error) {
        if params.Filter == "" {
        return c.GetChildren(ctx, params.GroupID, params.PageNumber, params.PageSize)
        }
         
         
        Severity: Major
        Found in core/controller/group/controller.go - About 45 mins to fix

          Method controller.SearchGroups has 6 return statements (exceeds 4 allowed).
          Open

          func (c *controller) SearchGroups(ctx context.Context, params *SearchParams) ([]*service.Child, int64, error) {
          if params.Filter == "" {
          return c.GetSubGroups(ctx, params.GroupID, params.PageNumber, params.PageSize)
          }
           
           
          Severity: Major
          Found in core/controller/group/controller.go - About 40 mins to fix

            Method controller.GetChildren has 5 return statements (exceeds 4 allowed).
            Open

            func (c *controller) GetChildren(ctx context.Context, id uint, pageNumber, pageSize int) (
            []*service.Child, int64, error) {
            var parent *models.Group
            var full *service.Full
            if id > 0 {
            Severity: Major
            Found in core/controller/group/controller.go - About 35 mins to fix

              Method controller.GetSubGroups has 5 return statements (exceeds 4 allowed).
              Open

              func (c *controller) GetSubGroups(ctx context.Context, id uint, pageNumber, pageSize int) (
              []*service.Child, int64, error) {
              var parent *models.Group
              var full *service.Full
              if id > 0 {
              Severity: Major
              Found in core/controller/group/controller.go - About 35 mins to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                for i, s := range subGroups {
                var fName, fPath string
                if id == 0 {
                fName = s.Name
                fPath = fmt.Sprintf("/%s", s.Path)
                Severity: Major
                Found in core/controller/group/controller.go and 1 other location - About 1 hr to fix
                core/controller/group/controller.go on lines 142..158

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                for i, val := range children {
                var fName, fPath string
                if id == 0 {
                fName = val.Name
                fPath = fmt.Sprintf("/%s", val.Path)
                Severity: Major
                Found in core/controller/group/controller.go and 1 other location - About 1 hr to fix
                core/controller/group/controller.go on lines 289..305

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                if ok && fmt.Sprintf("%s/%s", appParentFull.FullPath, app.Name) == resourcePath {
                return service.ConvertApplicationToChild(app, &service.Full{
                FullName: fmt.Sprintf("%s/%s", appParentFull.FullName, app.Name),
                FullPath: fmt.Sprintf("%s/%s", appParentFull.FullPath, app.Name),
                }), nil
                Severity: Minor
                Found in core/controller/group/controller.go and 1 other location - About 30 mins to fix
                core/controller/group/controller.go on lines 452..457

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                if ok && fmt.Sprintf("%s/%s", full.FullPath, template.Name) == resourcePath {
                return service.ConvertTemplateToChild(template, &service.Full{
                FullName: fmt.Sprintf("%s/%s", full.FullName, template.Name),
                FullPath: fmt.Sprintf("%s/%s", full.FullPath, template.Name),
                }), nil
                Severity: Minor
                Found in core/controller/group/controller.go and 1 other location - About 30 mins to fix
                core/controller/group/controller.go on lines 391..396
                Category
                Status