model_struct.go

Summary

Maintainability
F
2 wks
Test Coverage

Method Scope.getModelStruct has a Cognitive Complexity of 765 (exceeds 20 allowed). Consider refactoring.
Open

func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) *ModelStruct {
    var modelStruct ModelStruct
    // Scope value can't be nil
    if scope.Value == nil {
        return &modelStruct
Severity: Minor
Found in model_struct.go - About 2 wks to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method Scope.getModelStruct has 392 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) *ModelStruct {
    var modelStruct ModelStruct
    // Scope value can't be nil
    if scope.Value == nil {
        return &modelStruct
Severity: Major
Found in model_struct.go - About 1 day to fix

    File model_struct.go has 537 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package gorm
    
    import (
        "database/sql"
        "errors"
    Severity: Minor
    Found in model_struct.go - About 2 hrs to fix

      Method Scope.getModelStruct has 7 return statements (exceeds 4 allowed).
      Open

      func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) *ModelStruct {
          var modelStruct ModelStruct
          // Scope value can't be nil
          if scope.Value == nil {
              return &modelStruct
      Severity: Major
      Found in model_struct.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                        } else if _, isTime := fieldValue.(*time.Time); isTime {
                            // is time
                            field.IsNormal = true
                        } else if _, ok := field.TagSettingsGet("EMBEDDED"); ok || fieldStruct.Anonymous {
                            // is embedded struct
        Severity: Major
        Found in model_struct.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if indirectType.Kind() == reflect.Struct {
                                  for i := 0; i < indirectType.NumField(); i++ {
                                      for key, value := range parseTagSetting(indirectType.Field(i).Tag) {
                                          if _, ok := field.TagSettingsGet(key); !ok {
                                              field.TagSettingsSet(key, value)
          Severity: Major
          Found in model_struct.go - About 45 mins to fix

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

                                                if len(foreignKeys) == 0 {
                                                    // if no association foreign keys defined with tag
                                                    if len(associationForeignKeys) == 0 {
                                                        for _, field := range modelStruct.PrimaryFields {
                                                            foreignKeys = append(foreignKeys, associationType+field.Name)
            Severity: Major
            Found in model_struct.go and 1 other location - About 4 hrs to fix
            model_struct.go on lines 500..534

            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 309.

            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

                                            if len(foreignKeys) == 0 {
                                                // if no association foreign keys defined with tag
                                                if len(associationForeignKeys) == 0 {
                                                    for _, primaryField := range modelStruct.PrimaryFields {
                                                        foreignKeys = append(foreignKeys, associationType+primaryField.Name)
            Severity: Major
            Found in model_struct.go and 1 other location - About 4 hrs to fix
            model_struct.go on lines 392..426

            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 309.

            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

                                            for idx, foreignKey := range foreignKeys {
                                                if foreignField := getForeignField(foreignKey, toFields); foreignField != nil {
                                                    if scopeField := getForeignField(associationForeignKeys[idx], allFields); scopeField != nil {
                                                        // mark field as foreignkey, use global lock to avoid race
                                                        structsLock.Lock()
            Severity: Major
            Found in model_struct.go and 1 other location - About 1 hr to fix
            model_struct.go on lines 428..445

            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 171.

            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

                                                for idx, foreignKey := range foreignKeys {
                                                    if foreignField := getForeignField(foreignKey, toFields); foreignField != nil {
                                                        if associationField := getForeignField(associationForeignKeys[idx], allFields); associationField != nil {
                                                            // mark field as foreignkey, use global lock to avoid race
                                                            structsLock.Lock()
            Severity: Major
            Found in model_struct.go and 1 other location - About 1 hr to fix
            model_struct.go on lines 536..553

            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 171.

            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

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

                                                if polymorphic, _ := field.TagSettingsGet("POLYMORPHIC"); polymorphic != "" {
                                                    // Dog has many toys, tag polymorphic is Owner, then associationType is Owner
                                                    // Toy use OwnerID, OwnerType ('dogs') as foreign key
                                                    if polymorphicType := getForeignField(polymorphic+"Type", toFields); polymorphicType != nil {
                                                        associationType = polymorphic
            Severity: Major
            Found in model_struct.go and 1 other location - About 1 hr to fix
            model_struct.go on lines 478..493

            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 138.

            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

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

                                        if polymorphic, _ := field.TagSettingsGet("POLYMORPHIC"); polymorphic != "" {
                                            // Cat has one toy, tag polymorphic is Owner, then associationType is Owner
                                            // Toy use OwnerID, OwnerType ('cats') as foreign key
                                            if polymorphicType := getForeignField(polymorphic+"Type", toFields); polymorphicType != nil {
                                                associationType = polymorphic
            Severity: Major
            Found in model_struct.go and 1 other location - About 1 hr to fix
            model_struct.go on lines 374..389

            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 138.

            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

                                                        if field, ok := toScope.FieldByName(name); ok {
                                                            // association foreign keys (db names)
                                                            relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, field.DBName)
            
                                                            // setup join table foreign keys for association
            Severity: Minor
            Found in model_struct.go and 1 other location - About 40 mins to fix
            model_struct.go on lines 317..329

            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 109.

            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

                                                        if foreignField := getForeignField(foreignKey, modelStruct.StructFields); foreignField != nil {
                                                            // source foreign keys (db names)
                                                            relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.DBName)
            
                                                            // setup join table foreign keys for source
            Severity: Minor
            Found in model_struct.go and 1 other location - About 40 mins to fix
            model_struct.go on lines 348..360

            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 109.

            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