Showing 96 of 96 total issues

Avoid deeply nested control flow statements.
Open

                    for j := 0; j < result.Len(); j++ {
                        if elem := result.Index(j); elem.CanAddr() && resultsMap[elem.Addr()] != true {
                            resultsMap[elem.Addr()] = true
                            results = reflect.Append(results, elem.Addr())
                        }
Severity: Major
Found in scope.go - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                            if t.IsZero() {
                                formattedValues = append(formattedValues, fmt.Sprintf("'%v'", "0000-00-00 00:00:00"))
                            } else {
                                formattedValues = append(formattedValues, fmt.Sprintf("'%v'", t.Format("2006-01-02 15:04:05")))
                            }
    Severity: Major
    Found in logger.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if relationship.JoinTableHandler == nil && len(relationship.ForeignFieldNames) != 0 {
                                  for idx, fieldName := range relationship.ForeignFieldNames {
                                      associationForeignName := relationship.AssociationForeignDBNames[idx]
                                      if f, ok := scope.FieldByName(associationForeignName); ok {
                                          scope.Err(newScope.SetColumn(fieldName, f.Field.Interface()))
      Severity: Major
      Found in callback_save.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if !field.IsForeignKey || !field.IsBlank || !field.HasDefaultValue {
                                    sqls = append(sqls, fmt.Sprintf("%v = %v", scope.Quote(field.DBName), scope.AddToVars(field.Field.Interface())))
                                }
        Severity: Major
        Found in callback_update.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              } else if autoUpdate {
                                  scope.Err(newDB.Save(elem).Error)
                              }
          Severity: Major
          Found in callback_save.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                } else if relationship := field.Relationship; relationship != nil && relationship.Kind == "belongs_to" {
                                    for _, foreignKey := range relationship.ForeignDBNames {
                                        if foreignField, ok := scope.FieldByName(foreignKey); ok && !scope.changeableField(foreignField) {
                                            sqls = append(sqls,
                                                fmt.Sprintf("%v = %v", scope.Quote(foreignField.DBName), scope.AddToVars(foreignField.Field.Interface())))
            Severity: Major
            Found in callback_update.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if err == ErrUnaddressable {
                                          results[field.DBName] = value
                                      } else {
                                          results[field.DBName] = field.Field.Interface()
                                      }
              Severity: Major
              Found in scope.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if primaryValue, err := result.LastInsertId(); scope.Err(err) == nil {
                                        scope.Err(primaryField.Set(primaryValue))
                                    }
                Severity: Major
                Found in callback_create.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if autoCreate {
                                              scope.Err(newDB.Save(elem).Error)
                                          }
                  Severity: Major
                  Found in callback_save.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if joinTableHandler := relationship.JoinTableHandler; joinTableHandler != nil {
                                                scope.Err(joinTableHandler.Add(joinTableHandler, newDB, scope.Value, newScope.Value))
                                            }
                    Severity: Major
                    Found in callback_save.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if foreignField, ok := scope.FieldByName(foreignKey); ok && !scope.changeableField(foreignField) {
                                                  columns = append(columns, scope.Quote(foreignField.DBName))
                                                  placeholders = append(placeholders, scope.AddToVars(foreignField.Field.Interface()))
                                              }
                      Severity: Major
                      Found in callback_create.go - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                        if valuer, ok := v.(driver.Valuer); ok {
                                            if v, err = valuer.Value(); err == nil {
                                                err = scanner.Scan(v)
                                            }
                                        } else {
                        Severity: Major
                        Found in field.go - About 45 mins to fix

                          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

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

                          func (scope *Scope) whereSQL() (sql string) {
                              var (
                                  quotedTableName                                = scope.QuotedTableName()
                                  deletedAtField, hasDeletedAtField              = scope.FieldByName("DeletedAt")
                                  primaryConditions, andConditions, orConditions []string
                          Severity: Minor
                          Found in scope.go - About 35 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

                          Function convertInterfaceToMap has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                          Open

                          func convertInterfaceToMap(values interface{}, withIgnoredField bool, db *DB) map[string]interface{} {
                              var attrs = map[string]interface{}{}
                          
                              switch value := values.(type) {
                              case map[string]interface{}:
                          Severity: Minor
                          Found in scope.go - About 25 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

                          Severity
                          Category
                          Status
                          Source
                          Language