Showing 96 of 96 total issues

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

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

                    for idx, fieldName := range relationship.AssociationForeignFieldNames {
                        if field, ok := toScope.FieldByName(fieldName); ok {
                            foreignKeyStruct := field.clone()
                            foreignKeyStruct.IsPrimaryKey = false
                            foreignKeyStruct.TagSettingsSet("IS_JOINTABLE_FOREIGNKEY", "true")
        Severity: Major
        Found in scope.go and 1 other location - About 1 hr to fix
        scope.go on lines 1143..1152

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

        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, fieldName := range relationship.ForeignFieldNames {
                        if field, ok := scope.FieldByName(fieldName); ok {
                            foreignKeyStruct := field.clone()
                            foreignKeyStruct.IsPrimaryKey = false
                            foreignKeyStruct.TagSettingsSet("IS_JOINTABLE_FOREIGNKEY", "true")
        Severity: Major
        Found in scope.go and 1 other location - About 1 hr to fix
        scope.go on lines 1154..1163

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

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

          Method Association.saveAssociations has 56 lines of code (exceeds 50 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

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

                    if lastInsertIDReturningSuffix == "" && lastInsertIDOutputInterstitial == "" {
                        if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
                            // set rows affected count
                            scope.db.RowsAffected, _ = result.RowsAffected()
            
            
            Severity: Major
            Found in callback_create.go and 1 other location - About 1 hr to fix
            callback_create.go on lines 132..145

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

            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 primaryField == nil {
                        if result, err := scope.SQLDB().Exec(scope.SQL, scope.SQLVars...); scope.Err(err) == nil {
                            // set rows affected count
                            scope.db.RowsAffected, _ = result.RowsAffected()
            
            
            Severity: Major
            Found in callback_create.go and 1 other location - About 1 hr to fix
            callback_create.go on lines 148..161

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

            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 name, ok := field.TagSettingsGet("INDEX"); ok {
                        names := strings.Split(name, ",")
            
                        for _, name := range names {
                            if name == "INDEX" || name == "" {
            Severity: Major
            Found in scope.go and 1 other location - About 1 hr to fix
            scope.go on lines 1306..1316

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

            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 name, ok := field.TagSettingsGet("UNIQUE_INDEX"); ok {
                        names := strings.Split(name, ",")
            
                        for _, name := range names {
                            if name == "UNIQUE_INDEX" || name == "" {
            Severity: Major
            Found in scope.go and 1 other location - About 1 hr to fix
            scope.go on lines 1294..1304

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

            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

            Function saveAssociationCheck has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
            Open

            func saveAssociationCheck(scope *Scope, field *Field) (autoUpdate bool, autoCreate bool, saveReference bool, r *Relationship) {
                checkTruth := func(value interface{}) bool {
                    if v, ok := value.(bool); ok && !v {
                        return false
                    }
            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 search.clone has 52 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (s *search) clone() *search {
                clone := search{
                    db:               s.db,
                    whereConditions:  make([]map[string]interface{}, len(s.whereConditions)),
                    orConditions:     make([]map[string]interface{}, len(s.orConditions)),
            Severity: Minor
            Found in search.go - About 1 hr to fix

              Method sqlite3.DataTypeOf has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
              Open

              func (s *sqlite3) DataTypeOf(field *StructField) string {
                  var dataValue, sqlType, size, additionalType = ParseFieldStructForDialect(field, s)
              
                  if sqlType == "" {
                      switch dataValue.Kind() {
              Severity: Minor
              Found in dialect_sqlite3.go - About 55 mins 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 (s *DB) Last(out interface{}, where ...interface{}) *DB {
                  newScope := s.NewScope(out)
                  newScope.Search.Limit(1)
                  return newScope.Set("gorm:order_by_primary_key", "DESC").
                      inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db
              Severity: Minor
              Found in main.go and 1 other location - About 50 mins to fix
              main.go on lines 332..338

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

              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 (s *DB) First(out interface{}, where ...interface{}) *DB {
                  newScope := s.NewScope(out)
                  newScope.Search.Limit(1)
              
                  return newScope.Set("gorm:order_by_primary_key", "ASC").
              Severity: Minor
              Found in main.go and 1 other location - About 50 mins to fix
              main.go on lines 348..353

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

              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