Showing 96 of 96 total issues

Function createCallback has 103 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func createCallback(scope *Scope) {
    if !scope.HasError() {
        defer scope.trace(NowFunc())

        var (
Severity: Major
Found in callback_create.go - About 3 hrs to fix

    Function queryCallback has a Cognitive Complexity of 37 (exceeds 20 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 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

    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

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

            func init() {
                DefaultCallback.Update().Register("gorm:assign_updating_attributes", assignUpdatingAttributesCallback)
                DefaultCallback.Update().Register("gorm:begin_transaction", beginTransactionCallback)
                DefaultCallback.Update().Register("gorm:before_update", beforeUpdateCallback)
                DefaultCallback.Update().Register("gorm:save_before_associations", saveBeforeAssociationsCallback)
            Severity: Major
            Found in callback_update.go and 1 other location - About 1 hr to fix
            callback_create.go on lines 9..19

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

            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 init() {
                DefaultCallback.Create().Register("gorm:begin_transaction", beginTransactionCallback)
                DefaultCallback.Create().Register("gorm:before_create", beforeCreateCallback)
                DefaultCallback.Create().Register("gorm:save_before_associations", saveBeforeAssociationsCallback)
                DefaultCallback.Create().Register("gorm:update_time_stamp", updateTimeStampForCreateCallback)
            Severity: Major
            Found in callback_create.go and 1 other location - About 1 hr to fix
            callback_update.go on lines 11..21

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

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

              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

              Severity
              Category
              Status
              Source
              Language