Showing 76 of 96 total issues

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

    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

      Method Scope.getModelStruct has 7 return statements (exceeds 4 allowed).
      Open

      func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) *ModelStruct {
          var modelStruct ModelStruct
          // Scope value can't be nil
          if scope.Value == nil {
              return &modelStruct
      Severity: Major
      Found in model_struct.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if len(arrayMarks) > 0 {
                                tempMarks = append(tempMarks, fmt.Sprintf("(%v)", strings.Join(arrayMarks, ",")))
                            }
        Severity: Major
        Found in scope.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                          } else if relationship.Kind == "has_many" || relationship.Kind == "has_one" {
                              for idx, foreignKey := range relationship.ForeignDBNames {
                                  if field, ok := scope.FieldByName(relationship.AssociationForeignDBNames[idx]); ok {
                                      tx = tx.Where(fmt.Sprintf("%v = ?", scope.Quote(foreignKey)), 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 isPtr {
                                      results.Set(reflect.Append(results, elem.Addr()))
                                  } else {
                                      results.Set(reflect.Append(results, elem))
                                  }
              Severity: Major
              Found in callback_query.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            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

                                  } else if result.CanAddr() && resultsMap[result.Addr()] != true {
                                      resultsMap[result.Addr()] = true
                                      results = reflect.Append(results, result.Addr())
                                  }
                  Severity: Major
                  Found in scope.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        } else if !field.IsPrimaryKey || !field.IsBlank {
                                            columns = append(columns, scope.Quote(field.DBName))
                                            placeholders = append(placeholders, scope.AddToVars(field.Field.Interface()))
                                        }
                    Severity: Major
                    Found in callback_create.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                      } else if _, isTime := fieldValue.(*time.Time); isTime {
                                          // is time
                                          field.IsNormal = true
                                      } else if _, ok := field.TagSettingsGet("EMBEDDED"); ok || fieldStruct.Anonymous {
                                          // is embedded struct
                      Severity: Major
                      Found in model_struct.go - About 45 mins to fix

                        Method Scope.buildCondition has 7 return statements (exceeds 4 allowed).
                        Open

                        func (scope *Scope) buildCondition(clause map[string]interface{}, include bool) (str string) {
                            var (
                                quotedTableName  = scope.QuotedTableName()
                                quotedPrimaryKey = scope.Quote(scope.PrimaryKey())
                                equalSQL         = "="
                        Severity: Major
                        Found in scope.go - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                      } else if values := reflect.ValueOf(arg); values.Len() > 0 {
                                          var tempMarks []string
                                          for i := 0; i < values.Len(); i++ {
                                              tempMarks = append(tempMarks, scope.AddToVars(values.Index(i).Interface()))
                                          }
                          Severity: Major
                          Found in scope.go - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                if cp.before == "" {
                                                    cp.before = c.name
                                                }
                            Severity: Major
                            Found in callback.go - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if relationship.PolymorphicType != "" {
                                                          scope.Err(newScope.SetColumn(relationship.PolymorphicType, relationship.PolymorphicValue))
                                                      }
                              Severity: Major
                              Found in callback_save.go - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                    if indirectType.Kind() == reflect.Struct {
                                                        for i := 0; i < indirectType.NumField(); i++ {
                                                            for key, value := range parseTagSetting(indirectType.Field(i).Tag) {
                                                                if _, ok := field.TagSettingsGet(key); !ok {
                                                                    field.TagSettingsSet(key, value)
                                Severity: Major
                                Found in model_struct.go - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                          if field, ok := scope.FieldByName(foreignKey); ok {
                                                              tx = tx.Where(fmt.Sprintf("%v = ?", scope.Quote(relationship.AssociationForeignDBNames[idx])), field.Field.Interface())
                                                          }
                                  Severity: Major
                                  Found in scope.go - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                    if len(tempMarks) > 0 {
                                                        replacements = append(replacements, strings.Join(tempMarks, ","))
                                                    }
                                    Severity: Major
                                    Found in scope.go - About 45 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language