horizoncd/horizon

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

Summary

Maintainability
D
2 days
Test Coverage

Method dao.ListV2 has 58 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (d dao) ListV2(ctx context.Context, query *q.Query, groupIDs ...uint) ([]*models.Template, error) {
    var templates []*models.Template

    statement := d.db.WithContext(ctx).
        Table("tb_template as t").
Severity: Minor
Found in pkg/template/dao/dao.go - About 1 hr to fix

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

    func (d dao) GetRefOfApplication(ctx context.Context, id uint) ([]*amodels.Application, uint, error) {
        onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
        var (
            applications []*amodels.Application
            total        uint
    Severity: Major
    Found in pkg/template/dao/dao.go and 3 other locations - About 4 hrs to fix
    pkg/template/dao/dao.go on lines 138..158
    pkg/templaterelease/dao/dao.go on lines 108..128
    pkg/templaterelease/dao/dao.go on lines 130..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 320.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) GetRefOfCluster(ctx context.Context, id uint) ([]*cmodel.Cluster, uint, error) {
        onlyRefCount, ok := ctx.Value(hctx.TemplateOnlyRefCount).(bool)
        var (
            clusters []*cmodel.Cluster
            total    uint
    Severity: Major
    Found in pkg/template/dao/dao.go and 3 other locations - About 4 hrs to fix
    pkg/template/dao/dao.go on lines 116..136
    pkg/templaterelease/dao/dao.go on lines 108..128
    pkg/templaterelease/dao/dao.go on lines 130..150

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 320.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) GetByID(ctx context.Context, id uint) (*models.Template, error) {
        var template models.Template
        res := d.db.Raw(dbsql.TemplateQueryByID, id).First(&template)
        if res.Error != nil {
            if res.Error == gorm.ErrRecordNotFound {
    Severity: Major
    Found in pkg/template/dao/dao.go and 1 other location - About 2 hrs to fix
    pkg/template/dao/dao.go on lines 102..114

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 221.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) GetByName(ctx context.Context, name string) (*models.Template, error) {
        var template models.Template
        res := d.db.Raw(dbsql.TemplateQueryByName, name).First(&template)
        if res.Error != nil {
            if res.Error == gorm.ErrRecordNotFound {
    Severity: Major
    Found in pkg/template/dao/dao.go and 1 other location - About 2 hrs to fix
    pkg/template/dao/dao.go on lines 88..100

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 221.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) ListByGroupIDs(ctx context.Context, ids []uint) ([]*models.Template, error) {
        templates := make([]*models.Template, 0)
        res := d.db.Where("group_id in ?", ids).Find(&templates)
        if res.Error != nil {
            return nil, perror.Wrapf(herrors.NewErrGetFailed(herrors.TemplateInDB, res.Error.Error()),
    Severity: Major
    Found in pkg/template/dao/dao.go and 1 other location - About 1 hr to fix
    pkg/template/dao/dao.go on lines 200..209

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) ListByIDs(ctx context.Context, ids []uint) ([]*models.Template, error) {
        templates := make([]*models.Template, 0)
        res := d.db.Where("id in ?", ids).Find(&templates)
        if res.Error != nil {
            return nil, perror.Wrapf(herrors.NewErrGetFailed(herrors.TemplateInDB, res.Error.Error()),
    Severity: Major
    Found in pkg/template/dao/dao.go and 1 other location - About 1 hr to fix
    pkg/template/dao/dao.go on lines 189..198

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 162.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    func (d dao) DeleteByID(ctx context.Context, id uint) error {
        if res := d.db.Exec(dbsql.TemplateDelete, id); res.Error != nil {
            return perror.Wrap(herrors.NewErrDeleteFailed(herrors.TemplateInDB, res.Error.Error()),
                fmt.Sprintf("failed to delete template, id = %d", id))
        }
    Severity: Minor
    Found in pkg/template/dao/dao.go and 1 other location - About 55 mins to fix
    pkg/templaterelease/dao/dao.go on lines 159..165

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 123.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status