Showing 96 of 96 total issues

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

func (s mysql) HasColumn(tableName string, columnName string) bool {
    currentDatabase, tableName := currentDatabaseAndTable(&s, tableName)
    if rows, err := s.db.Query(fmt.Sprintf("SHOW COLUMNS FROM `%s` FROM `%s` WHERE Field = ?", tableName, currentDatabase), columnName); err != nil {
        panic(err)
    } else {
Severity: Minor
Found in dialect_mysql.go and 1 other location - About 45 mins to fix
dialect_mysql.go on lines 186..194

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

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 mysql) HasIndex(tableName string, indexName string) bool {
    currentDatabase, tableName := currentDatabaseAndTable(&s, tableName)
    if rows, err := s.db.Query(fmt.Sprintf("SHOW INDEXES FROM `%s` FROM `%s` WHERE Key_name = ?", tableName, currentDatabase), indexName); err != nil {
        panic(err)
    } else {
Severity: Minor
Found in dialect_mysql.go and 1 other location - About 45 mins to fix
dialect_mysql.go on lines 196..204

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

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

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

                  } 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

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

                                      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

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

                          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

                                                    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

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

                                                          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

                                                    } 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
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language