Showing 96 of 96 total issues

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

File scope.go has 1189 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package gorm

import (
    "bytes"
    "database/sql"
Severity: Major
Found in scope.go - About 2 days to fix

    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

      Function saveAfterAssociationsCallback has a Cognitive Complexity of 106 (exceeds 20 allowed). Consider refactoring.
      Open

      func saveAfterAssociationsCallback(scope *Scope) {
          for _, field := range scope.Fields() {
              autoUpdate, autoCreate, saveReference, relationship := saveAssociationCheck(scope, field)
      
              if relationship != nil && (relationship.Kind == "has_one" || relationship.Kind == "has_many" || relationship.Kind == "many_to_many") {
      Severity: Minor
      Found in callback_save.go - About 1 day 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

      DB has 89 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type DB struct {
          sync.RWMutex
          Value        interface{}
          Error        error
          RowsAffected int64
      Severity: Major
      Found in main.go - About 1 day to fix

        Scope has 78 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type Scope struct {
            Search          *search
            Value           interface{}
            SQL             string
            SQLVars         []interface{}
        Severity: Major
        Found in scope.go - About 1 day to fix

          Function createCallback has a Cognitive Complexity of 84 (exceeds 20 allowed). Consider refactoring.
          Open

          func createCallback(scope *Scope) {
              if !scope.HasError() {
                  defer scope.trace(NowFunc())
          
                  var (
          Severity: Minor
          Found in callback_create.go - About 1 day 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.buildCondition has a Cognitive Complexity of 79 (exceeds 20 allowed). Consider refactoring.
          Open

          func (scope *Scope) buildCondition(clause map[string]interface{}, include bool) (str string) {
              var (
                  quotedTableName  = scope.QuotedTableName()
                  quotedPrimaryKey = scope.Quote(scope.PrimaryKey())
                  equalSQL         = "="
          Severity: Minor
          Found in scope.go - About 1 day 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 mysql.DataTypeOf has a Cognitive Complexity of 60 (exceeds 20 allowed). Consider refactoring.
          Open

          func (s *mysql) DataTypeOf(field *StructField) string {
              var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
          
              // MySQL allows only one auto increment column per table, and it must
              // be a KEY column.
          Severity: Minor
          Found in dialect_mysql.go - About 6 hrs 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 Association.Delete has a Cognitive Complexity of 56 (exceeds 20 allowed). Consider refactoring.
          Open

          func (association *Association) Delete(values ...interface{}) *Association {
              if association.Error != nil {
                  return association
              }
          
          
          Severity: Minor
          Found in association.go - About 6 hrs 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 Association.Replace has a Cognitive Complexity of 53 (exceeds 20 allowed). Consider refactoring.
          Open

          func (association *Association) Replace(values ...interface{}) *Association {
              if association.Error != nil {
                  return association
              }
          
          
          Severity: Minor
          Found in association.go - About 5 hrs 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

          Function updateCallback has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
          Open

          func updateCallback(scope *Scope) {
              if !scope.HasError() {
                  var sqls []string
          
                  if updateAttrs, ok := scope.InstanceGet("gorm:update_attrs"); ok {
          Severity: Minor
          Found in callback_update.go - About 5 hrs 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

          File main.go has 618 lines of code (exceeds 500 allowed). Consider refactoring.
          Open

          package gorm
          
          import (
              "context"
              "database/sql"
          Severity: Minor
          Found in main.go - About 4 hrs to fix

            Function preloadCallback has a Cognitive Complexity of 46 (exceeds 20 allowed). Consider refactoring.
            Open

            func preloadCallback(scope *Scope) {
                if _, skip := scope.InstanceGet("gorm:skip_query_callback"); skip {
                    return
                }
            
            
            Severity: Minor
            Found in callback_query_preload.go - About 4 hrs 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

            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

            Method Scope.buildCondition has 124 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (scope *Scope) buildCondition(clause map[string]interface{}, include bool) (str string) {
                var (
                    quotedTableName  = scope.QuotedTableName()
                    quotedPrimaryKey = scope.Quote(scope.PrimaryKey())
                    equalSQL         = "="
            Severity: Major
            Found in scope.go - About 3 hrs to fix

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

              func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
                  toScope := scope.db.NewScope(value)
                  tx := scope.db.Set("gorm:association:source", scope.Value)
              
                  for _, foreignKey := range append(foreignKeys, toScope.typeName()+"Id", scope.typeName()+"Id") {
              Severity: Minor
              Found in scope.go - About 3 hrs 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.getColumnAsArray has a Cognitive Complexity of 41 (exceeds 20 allowed). Consider refactoring.
              Open

              func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
                  resultMap := make(map[string][]interface{})
                  for _, value := range values {
                      indirectValue := indirect(reflect.ValueOf(value))
              
              
              Severity: Minor
              Found in scope.go - About 3 hrs 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 postgres.DataTypeOf has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
              Open

              func (s *postgres) DataTypeOf(field *StructField) string {
                  var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
              
                  if sqlType == "" {
                      switch dataValue.Kind() {
              Severity: Minor
              Found in dialect_postgres.go - About 3 hrs 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

              Severity
              Category
              Status
              Source
              Language