resource/meta.go

Summary

Maintainability
F
4 days
Test Coverage

Function setupSetter has a Cognitive Complexity of 109 (exceeds 20 allowed). Consider refactoring.
Open

func setupSetter(meta *Meta, fieldName string, record interface{}) {
    nestedField := strings.Contains(fieldName, ".")

    // Setup nested fields
    if nestedField {
Severity: Minor
Found in resource/meta.go - About 1 day 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 setupSetter has 137 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func setupSetter(meta *Meta, fieldName string, record interface{}) {
    nestedField := strings.Contains(fieldName, ".")

    // Setup nested fields
    if nestedField {
Severity: Major
Found in resource/meta.go - About 4 hrs to fix

    File meta.go has 525 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package resource
    
    import (
        "database/sql"
        "errors"
    Severity: Minor
    Found in resource/meta.go - About 2 hrs to fix

      Function setupValuer has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
      Open

      func setupValuer(meta *Meta, fieldName string, record interface{}) {
          nestedField := strings.Contains(fieldName, ".")
      
          // Setup nested fields
          if nestedField {
      Severity: Minor
      Found in resource/meta.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

      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 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 len(relationship.ForeignFieldNames) == 2 {
                                            HandleVersioningBelongsTo(context, recordAsValue, field, relationship, primaryKeys, fieldHasVersion)
                                        }
                Severity: Major
                Found in resource/meta.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                          } else if _, ok := field.Addr().Interface().(*time.Time); ok {
                              meta.Setter = commonSetter(func(field reflect.Value, metaValue *MetaValue, context *qor.Context, record interface{}) {
                                  if str := utils.ToString(metaValue.Value); str != "" {
                                      if newTime, err := utils.ParseTime(str, context); err == nil {
                                          field.Set(reflect.ValueOf(newTime))
                  Severity: Major
                  Found in resource/meta.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if err := scanner.Scan(utils.ToString(metaValue.Value)); err != nil {
                                                context.AddError(err)
                                                return
                                            }
                    Severity: Major
                    Found in resource/meta.go - About 45 mins to fix

                      Function setupSetter has 6 return statements (exceeds 4 allowed).
                      Open

                      func setupSetter(meta *Meta, fieldName string, record interface{}) {
                          nestedField := strings.Contains(fieldName, ".")
                      
                          // Setup nested fields
                          if nestedField {
                      Severity: Major
                      Found in resource/meta.go - About 40 mins to fix

                        Function switchRecordToNewVersionIfNeeded has 6 return statements (exceeds 4 allowed).
                        Open

                        func switchRecordToNewVersionIfNeeded(context *qor.Context, record interface{}) interface{} {
                            if context.Request == nil {
                                return record
                            }
                        
                        
                        Severity: Major
                        Found in resource/meta.go - About 40 mins to fix

                          Function HandleBelongsTo has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

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

                            Function HandleNormalManyToMany has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            func HandleNormalManyToMany(context *qor.Context, field reflect.Value, metaValue *MetaValue, fieldHasVersion bool, compositePKeyConvertErr error) {
                            Severity: Minor
                            Found in resource/meta.go - About 35 mins to fix

                              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

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

                                  case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
                                      meta.Setter = commonSetter(func(field reflect.Value, metaValue *MetaValue, context *qor.Context, record interface{}) {
                                          field.SetInt(utils.ToInt(metaValue.Value))
                                      })
                              Severity: Minor
                              Found in resource/meta.go and 1 other location - About 35 mins to fix
                              resource/meta.go on lines 620..623

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

                              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

                                  case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
                                      meta.Setter = commonSetter(func(field reflect.Value, metaValue *MetaValue, context *qor.Context, record interface{}) {
                                          field.SetUint(utils.ToUint(metaValue.Value))
                                      })
                              Severity: Minor
                              Found in resource/meta.go and 1 other location - About 35 mins to fix
                              resource/meta.go on lines 616..619

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

                              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

                                      } else if reflect.TypeOf([]string{}).ConvertibleTo(field.Type()) {
                                          meta.Setter = commonSetter(func(field reflect.Value, metaValue *MetaValue, context *qor.Context, record interface{}) {
                                              field.Set(reflect.ValueOf(utils.ToArray(metaValue.Value)).Convert(field.Type()))
                                          })
                                      } else if _, ok := field.Addr().Interface().(*time.Time); ok {
                              Severity: Minor
                              Found in resource/meta.go and 1 other location - About 35 mins to fix
                              resource/meta.go on lines 653..671

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

                              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

                                      } else if reflect.TypeOf("").ConvertibleTo(field.Type()) {
                                          meta.Setter = commonSetter(func(field reflect.Value, metaValue *MetaValue, context *qor.Context, record interface{}) {
                                              field.Set(reflect.ValueOf(utils.ToString(metaValue.Value)).Convert(field.Type()))
                                          })
                                      } else if reflect.TypeOf([]string{}).ConvertibleTo(field.Type()) {
                              Severity: Minor
                              Found in resource/meta.go and 1 other location - About 35 mins to fix
                              resource/meta.go on lines 657..671

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

                              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

                              exported function HandleBelongsTo should have comment or be unexported
                              Open

                              func HandleBelongsTo(context *qor.Context, record reflect.Value, field reflect.Value, relationship *gorm.Relationship, primaryKeys []string) {
                              Severity: Minor
                              Found in resource/meta.go by golint

                              exported function CollectPrimaryKeys should have comment or be unexported
                              Open

                              func CollectPrimaryKeys(metaValueForCompositePrimaryKeys []string) (compositePKeys []CompositePrimaryKeyStruct, compositePKeyConvertErr error) {
                              Severity: Minor
                              Found in resource/meta.go by golint

                              exported function HandleManyToMany should have comment or be unexported
                              Open

                              func HandleManyToMany(context *qor.Context, scope *gorm.Scope, meta *Meta, record interface{}, metaValue *MetaValue, field reflect.Value, fieldHasVersion bool) {
                              Severity: Minor
                              Found in resource/meta.go by golint

                              comment on exported const CompositePrimaryKeyFieldName should be of the form "CompositePrimaryKeyFieldName ..."
                              Open

                              // CompositePrimaryKey the string that represents the composite primary key
                              Severity: Minor
                              Found in resource/meta.go by golint

                              exported function HandleVersioningBelongsTo should have comment or be unexported
                              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 by golint

                              Your code does not pass gofmt in 1 place. Go fmt your code!
                              Open

                              package resource
                              Severity: Minor
                              Found in resource/meta.go by gofmt

                              There are no issues that match your filters.

                              Category
                              Status