Showing 76 of 96 total issues

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 Association.Delete has 97 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (association *Association) Delete(values ...interface{}) *Association {
        if association.Error != nil {
            return association
        }
    
    
    Severity: Major
    Found in association.go - About 2 hrs to fix

      Method Scope.handleManyToManyPreload has 94 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (scope *Scope) handleManyToManyPreload(field *Field, conditions []interface{}) {
          var (
              relation         = field.Relationship
              joinTableHandler = relation.JoinTableHandler
              fieldType        = field.Struct.Type.Elem()
      Severity: Major
      Found in callback_query_preload.go - About 2 hrs to fix

        Function sortProcessors has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
        Open

        func sortProcessors(cps []*CallbackProcessor) []*func(scope *Scope) {
            var (
                allNames, sortedNames []string
                sortCallbackProcessor func(c *CallbackProcessor)
            )
        Severity: Minor
        Found in callback.go - About 2 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 mysql.DataTypeOf has 89 lines of code (exceeds 50 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: Major
        Found in dialect_mysql.go - About 2 hrs to fix

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

          func (scope *Scope) handleManyToManyPreload(field *Field, conditions []interface{}) {
              var (
                  relation         = field.Relationship
                  joinTableHandler = relation.JoinTableHandler
                  fieldType        = field.Struct.Type.Elem()
          Severity: Minor
          Found in callback_query_preload.go - About 2 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 defaultNamer has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
          Open

          func defaultNamer(name string) string {
              const (
                  lower = false
                  upper = true
              )
          Severity: Minor
          Found in naming.go - About 2 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.saveAssociations has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (association *Association) saveAssociations(values ...interface{}) *Association {
              var (
                  scope        = association.scope
                  field        = association.field
                  relationship = field.Relationship
          Severity: Minor
          Found in association.go - About 1 hr 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 mssql.DataTypeOf has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (s *mssql) DataTypeOf(field *gorm.StructField) string {
              var dataValue, sqlType, size, additionalType = gorm.ParseFieldStructForDialect(field, s)
          
              if sqlType == "" {
                  switch dataValue.Kind() {
          Severity: Minor
          Found in dialects/mssql/mssql.go - About 1 hr 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 Field.Set has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (field *Field) Set(value interface{}) (err error) {
              if !field.Field.IsValid() {
                  return errors.New("field value not valid")
              }
          
          
          Severity: Minor
          Found in field.go - About 1 hr 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 saveBeforeAssociationsCallback has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func saveBeforeAssociationsCallback(scope *Scope) {
              for _, field := range scope.Fields() {
                  autoUpdate, autoCreate, saveReference, relationship := saveAssociationCheck(scope, field)
          
                  if relationship != nil && relationship.Kind == "belongs_to" {
          Severity: Minor
          Found in callback_save.go - About 1 hr 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 commonDialect.DataTypeOf has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (s *commonDialect) DataTypeOf(field *StructField) string {
              var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
          
              if sqlType == "" {
                  switch dataValue.Kind() {
          Severity: Minor
          Found in dialect_common.go - About 1 hr 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.getColumnAsScope has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (scope *Scope) getColumnAsScope(column string) *Scope {
              indirectScopeValue := scope.IndirectValue()
          
              switch indirectScopeValue.Kind() {
              case reflect.Slice:
          Severity: Minor
          Found in scope.go - About 1 hr 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 69 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (association *Association) Replace(values ...interface{}) *Association {
              if association.Error != nil {
                  return association
              }
          
          
          Severity: Minor
          Found in association.go - About 1 hr to fix

            Function preloadCallback has 64 lines of code (exceeds 50 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 1 hr to fix

              Function queryCallback has 63 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func queryCallback(scope *Scope) {
                  if _, skip := scope.InstanceGet("gorm:skip_query_callback"); skip {
                      return
                  }
              
              
              Severity: Minor
              Found in callback_query.go - About 1 hr to fix

                Function saveAfterAssociationsCallback has 62 lines of code (exceeds 50 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 hr to fix

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

                  func (scope *Scope) autoIndex() *Scope {
                      var indexes = map[string][]string{}
                      var uniqueIndexes = map[string][]string{}
                  
                      for _, field := range scope.GetStructFields() {
                  Severity: Minor
                  Found in scope.go - About 1 hr 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 57 lines of code (exceeds 50 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 1 hr to fix

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

                    func (scope *Scope) updatedAttrsWithValues(value interface{}) (results map[string]interface{}, hasUpdate bool) {
                        if scope.IndirectValue().Kind() != reflect.Struct {
                            return convertInterfaceToMap(value, false, scope.db), true
                        }
                    
                    
                    Severity: Minor
                    Found in scope.go - About 1 hr 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