Showing 93 of 93 total issues

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

    for _, p := range associatedProducts {
        if p.ID == p1.ID && p.CompositePrimaryKey == fmt.Sprintf("%d%s%s", p1.ID, resource.CompositePrimaryKeySeparator, p1.GetVersionName()) {
            i += 1
        }

Severity: Major
Found in resource/meta_test.go and 1 other location - About 1 hr to fix
resource/meta_test.go on lines 625..633

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

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 _, c := range cases {
        // u, _ := url.Parse(c.original)
        // context := Context{Context: &qor.Context{Request: &http.Request{URL: u}}}
        got, err := PatchURL(c.original, c.input...)
        if c.err != nil {
Severity: Major
Found in utils/utils_test.go and 1 other location - About 1 hr to fix
utils/utils_test.go on lines 125..141

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

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 _, c := range cases {
        // u, _ := url.Parse(c.original)
        // context := Context{Context: &qor.Context{Request: &http.Request{URL: u}}}
        got, err := JoinURL(c.original, c.input...)
        if c.err != nil {
Severity: Major
Found in utils/utils_test.go and 1 other location - About 1 hr to fix
utils/utils_test.go on lines 68..84

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

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

type Meta struct {
    Name            string
    FieldName       string
    FieldStruct     *gorm.StructField
    Setter          func(resource interface{}, metaValue *MetaValue, context *qor.Context)
Severity: Major
Found in resource/meta.go and 1 other location - About 1 hr to fix
resource/crud.go on lines 41..50

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

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 ParamsMatch has 55 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func ParamsMatch(source string, pth string) (url.Values, string, bool) {
    var (
        i, j int
        p    = make(url.Values)
        ext  = path.Ext(pth)
Severity: Minor
Found in utils/params.go - About 1 hr to fix

    Function TestJoinURL has 52 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func TestJoinURL(t *testing.T) {
        var cases = []struct {
            original string
            input    []interface{}
            want     string
    Severity: Minor
    Found in utils/utils_test.go - About 1 hr to fix

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

      func TestFloatMetaValuerAndSetter(t *testing.T) {
          user := &struct {
              Age  float64
              Age2 *float64
          }{}
      Severity: Minor
      Found in resource/meta_test.go and 1 other location - About 55 mins to fix
      resource/meta_test.go on lines 60..81

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

      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 TestStringMetaValuerAndSetter(t *testing.T) {
          user := &struct {
              Name  string
              Name2 *string
          }{}
      Severity: Minor
      Found in resource/meta_test.go and 1 other location - About 55 mins to fix
      resource/meta_test.go on lines 122..143

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

      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 (coll *CollectionWithVersionAndUint64PrimaryKey) AssignVersionName(db *gorm.DB) {
          var count int
          name := time.Now().Format("2006-01-02")
          db.Model(&CollectionWithVersionAndUint64PrimaryKey{}).Where("id = ? AND version_name like ?", coll.ID, name+"%").Count(&count)
          coll.VersionName = fmt.Sprintf("%s-v%v", name, count+1)
      Severity: Minor
      Found in resource/meta_test.go and 1 other location - About 55 mins to fix
      resource/meta_test.go on lines 315..320

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

      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 (coll *CollectionWithVersion) AssignVersionName(db *gorm.DB) {
          var count int
          name := time.Now().Format("2006-01-02")
          db.Model(&CollectionWithVersion{}).Where("id = ? AND version_name like ?", coll.ID, name+"%").Count(&count)
          coll.VersionName = fmt.Sprintf("%s-v%v", name, count+1)
      Severity: Minor
      Found in resource/meta_test.go and 1 other location - About 55 mins to fix
      resource/meta_test.go on lines 322..327

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

      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 convertMapToMetaValues has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func convertMapToMetaValues(values map[string]interface{}, metaors []Metaor) (*MetaValues, error) {
          metaValues := &MetaValues{}
          metaorMap := make(map[string]Metaor)
          for _, metaor := range metaors {
              metaorMap[metaor.GetName()] = metaor
      Severity: Minor
      Found in resource/schema.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

      Function HandleManyToMany has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      func HandleManyToMany(context *qor.Context, scope *gorm.Scope, meta *Meta, record interface{}, metaValue *MetaValue, field reflect.Value, fieldHasVersion bool) {
      Severity: Major
      Found in resource/meta.go - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if reg, err := regexp.Compile("^" + match + "$"); err == nil && reg.MatchString(val) {
                                j = j + index + 1
                            } else {
                                return nil, "", false
                            }
        Severity: Major
        Found in utils/params.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if len(relationship.ForeignFieldNames) == 1 {
                                      HandleBelongsTo(context, recordAsValue, field, relationship, primaryKeys)
                                  }
          Severity: Major
          Found in resource/meta.go - About 45 mins to fix

            Function HandleVersioningBelongsTo has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            func HandleVersioningBelongsTo(context *qor.Context, record reflect.Value, field reflect.Value, relationship *gorm.Relationship, primaryKeys []string, fieldHasVersion bool) {
            Severity: Minor
            Found in resource/meta.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if metaValue.Value == nil {
                                          primaryKeys = []string{}
                                      }
              Severity: Major
              Found in resource/meta.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    } else if (relationship.Kind == "has_one" || relationship.Kind == "belongs_to") && context.GetDB().NewScope(f.Field.Interface()).PrimaryKeyZero() {
                                        if f.Field.Kind() == reflect.Ptr && f.Field.IsNil() {
                                            f.Field.Set(reflect.New(f.Field.Type().Elem()))
                                        }
                
                
                Severity: Major
                Found in resource/meta.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if fmt.Sprint(destroy.Value) != "0" && res.HasPermission(roles.Delete, context) {
                                          context.GetDB().Delete(result, append([]interface{}{primaryQuerySQL}, primaryParams...)...)
                                          return ErrProcessorSkipLeft
                                      }
                  Severity: Major
                  Found in resource/crud.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if isPtr {
                                        field.Set(reflect.Append(field, value))
                                    } else {
                                        field.Set(reflect.Append(field, value.Elem()))
                                    }
                    Severity: Major
                    Found in resource/meta_value.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if len(relationship.ForeignFieldNames) == 2 {
                                                  HandleVersioningBelongsTo(context, recordAsValue, field, relationship, primaryKeys, fieldHasVersion)
                                              }
                      Severity: Major
                      Found in resource/meta.go - About 45 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language