Showing 76 of 96 total issues

Avoid deeply nested control flow statements.
Open

            } else if reflectValue.Type().Elem().AssignableTo(fieldType.Elem()) {
                // if field's type is slice of struct, then need to set value back to argument after save
                setSliceFieldBackToValue = true
                field.Set(reflect.Append(field.Field, reflectValue.Elem()))
            }
Severity: Major
Found in association.go - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        } else if b, ok := value.([]byte); ok {
                            if str := string(b); isPrintable(str) {
                                formattedValues = append(formattedValues, fmt.Sprintf("'%v'", str))
                            } else {
                                formattedValues = append(formattedValues, "'<binary>'")
    Severity: Major
    Found in logger.go - About 45 mins to fix

      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

                              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