horizoncd/horizon

View on GitHub
pkg/cluster/dao/dao.go

Summary

Maintainability
C
1 day
Test Coverage

Showing 7 of 7 total issues

Method dao.List has 101 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (d *dao) List(ctx context.Context, query *q.Query, userID uint,
withRegion bool, appIDs ...uint) (int, []*models.ClusterWithRegion, error) {
var (
clusters []*models.ClusterWithRegion
total int64
Severity: Major
Found in pkg/cluster/dao/dao.go - About 3 hrs to fix

    Method dao.List has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
    Open

    func (d *dao) List(ctx context.Context, query *q.Query, userID uint,
    withRegion bool, appIDs ...uint) (int, []*models.ClusterWithRegion, error) {
    var (
    clusters []*models.ClusterWithRegion
    total int64
    Severity: Minor
    Found in pkg/cluster/dao/dao.go - About 2 hrs to fix

    Method dao.Create has 62 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (d *dao) Create(ctx context.Context, cluster *models.Cluster,
    tags []*tagmodels.Tag, extraMembers map[*usermodels.User]string) (*models.Cluster, error) {
    currentUser, err := common.UserFromContext(ctx)
    if err != nil {
    return nil, err
    Severity: Minor
    Found in pkg/cluster/dao/dao.go - About 1 hr to fix

      Method dao.Create has 8 return statements (exceeds 4 allowed).
      Open

      func (d *dao) Create(ctx context.Context, cluster *models.Cluster,
      tags []*tagmodels.Tag, extraMembers map[*usermodels.User]string) (*models.Cluster, error) {
      currentUser, err := common.UserFromContext(ctx)
      if err != nil {
      return nil, err
      Severity: Major
      Found in pkg/cluster/dao/dao.go - About 50 mins to fix

        Method dao.UpdateByID has 6 return statements (exceeds 4 allowed).
        Open

        func (d *dao) UpdateByID(ctx context.Context, id uint, cluster *models.Cluster) (*models.Cluster, error) {
        var clusterInDB models.Cluster
        if err := d.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
        // 1. get application in db first
        result := tx.Raw(sqlcommon.ClusterQueryByID, id).Scan(&clusterInDB)
        Severity: Major
        Found in pkg/cluster/dao/dao.go - About 40 mins to fix

          Method dao.List has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          func (d *dao) List(ctx context.Context, query *q.Query, userID uint,
          withRegion bool, appIDs ...uint) (int, []*models.ClusterWithRegion, error) {
          Severity: Minor
          Found in pkg/cluster/dao/dao.go - About 35 mins to fix

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

            func (d *dao) GetByNameFuzzily(ctx context.Context, name string, includeSoftDelete bool) ([]*models.Cluster, error) {
            var clusters []*models.Cluster
             
            statement := d.db.Unscoped().WithContext(ctx).Where("name like ?", fmt.Sprintf("%%%s%%", name))
            if !includeSoftDelete {
            Severity: Major
            Found in pkg/cluster/dao/dao.go and 1 other location - About 2 hrs to fix
            pkg/application/dao/dao.go on lines 80..97
            Category
            Status