Unleash/unleash-client-go

View on GitHub

Showing 138 of 138 total issues

Function NewClient has 105 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func NewClient(options ...ConfigOption) (*Client, error) {

    errChannels := errorChannels{
        errors:   make(chan error, 3),
        warnings: make(chan error, 3),
Severity: Major
Found in client.go - About 3 hrs to fix

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

    package strategies
    
    import (
        "github.com/Unleash/unleash-client-go/v3/context"
        "github.com/Unleash/unleash-client-go/v3/strategy"
    Severity: Major
    Found in internal/strategies/gradual_rollout_session_id.go and 1 other location - About 3 hrs to fix
    internal/strategies/gradual_rollout_user_id.go on lines 1..44

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

    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

    package strategies
    
    import (
        "github.com/Unleash/unleash-client-go/v3/context"
        "github.com/Unleash/unleash-client-go/v3/strategy"
    Severity: Major
    Found in internal/strategies/gradual_rollout_user_id.go and 1 other location - About 3 hrs to fix
    internal/strategies/gradual_rollout_session_id.go on lines 1..44

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

    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

    Method Client.isEnabled has 73 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.StrategyResult {
        var opts featureOption
        for _, o := range options {
            o(&opts)
        }
    Severity: Minor
    Found in client.go - About 1 hr to fix

      Method Client.isEnabled has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
      Open

      func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.StrategyResult {
          var opts featureOption
          for _, o := range options {
              o(&opts)
          }
      Severity: Minor
      Found in client.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 Client.isEnabled has 9 return statements (exceeds 4 allowed).
      Open

      func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.StrategyResult {
          var opts featureOption
          for _, o := range options {
              o(&opts)
          }
      Severity: Major
      Found in client.go - About 55 mins to fix

        Method Client.isParentDependencySatisfied has 8 return statements (exceeds 4 allowed).
        Open

        func (uc *Client) isParentDependencySatisfied(feature *api.Feature, context context.Context) bool {
            warnOnce := &WarnOnce{}
        
            dependenciesSatisfied := func(parent api.Dependency) bool {
                parentToggle := uc.repository.getToggle(parent.Feature)
        Severity: Major
        Found in client.go - About 50 mins to fix

          Method Client.getVariantWithoutMetrics has 8 return statements (exceeds 4 allowed).
          Open

          func (uc *Client) getVariantWithoutMetrics(feature string, options ...VariantOption) *api.Variant {
              defaultVariant := api.GetDefaultVariant()
              var opts variantOption
              for _, o := range options {
                  o(&opts)
          Severity: Major
          Found in client.go - About 50 mins to fix

            Avoid deeply nested control flow statements.
            Open

                } else if s, isString := param.(string); isString {
                    f, err := strconv.ParseFloat(s, 64)
                    if err == nil {
                        result, ok = f, true
                    }
            Severity: Major
            Found in internal/strategies/helpers.go - About 45 mins to fix

              Method repository.fetch has 6 return statements (exceeds 4 allowed).
              Open

              func (r *repository) fetch() error {
                  u, _ := r.options.url.Parse(getFetchURLPath(r.options.projectName))
              
                  req, err := http.NewRequest("GET", u.String(), nil)
                  if err != nil {
              Severity: Major
              Found in repository.go - About 40 mins to fix

                Method remoteAddressStrategy.IsEnabled has 6 return statements (exceeds 4 allowed).
                Open

                func (s remoteAddressStrategy) IsEnabled(params map[string]interface{}, ctx *context.Context) bool {
                    value, found := params[strategy.ParamIps]
                    if !found {
                        return false
                    }
                Severity: Major
                Found in internal/strategies/remote_addresss.go - About 40 mins to fix

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

                  func getSeed(ctx *context.Context, stickiness string) string {
                      if stickiness != "default" && stickiness != "" {
                          value := ctx.Field(stickiness)
                          if value == "" {
                              return strconv.Itoa(rand.Intn(10000))
                  Severity: Major
                  Found in api/feature.go - About 40 mins to fix

                    Method gradualRolloutSessionId.IsEnabled has 5 return statements (exceeds 4 allowed).
                    Open

                    func (s gradualRolloutSessionId) IsEnabled(params map[string]interface{}, ctx *context.Context) bool {
                        if ctx == nil || ctx.SessionId == "" {
                            return false
                        }
                    
                    
                    Severity: Major
                    Found in internal/strategies/gradual_rollout_session_id.go - About 35 mins to fix

                      Method gradualRolloutUserId.IsEnabled has 5 return statements (exceeds 4 allowed).
                      Open

                      func (s gradualRolloutUserId) IsEnabled(params map[string]interface{}, ctx *context.Context) bool {
                          if ctx == nil || ctx.UserId == "" {
                              return false
                          }
                      
                      
                      Severity: Major
                      Found in internal/strategies/gradual_rollout_user_id.go - About 35 mins to fix

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

                        func operatorNumEq(ctx *context.Context, constraint api.Constraint) (bool, error) {
                            return operatorNum(ctx, constraint, func(context *big.Float, constraint *big.Float) bool {
                                return context.Cmp(constraint) == 0
                            })
                        }
                        Severity: Major
                        Found in internal/constraints/operator_num.go and 4 other locations - About 30 mins to fix
                        internal/constraints/operator_num.go on lines 15..19
                        internal/constraints/operator_num.go on lines 21..25
                        internal/constraints/operator_num.go on lines 27..31
                        internal/constraints/operator_num.go on lines 33..37

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

                        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 5 locations. Consider refactoring.
                        Open

                        func operatorNumLte(ctx *context.Context, constraint api.Constraint) (bool, error) {
                            return operatorNum(ctx, constraint, func(context *big.Float, constraint *big.Float) bool {
                                return context.Cmp(constraint) <= 0
                            })
                        }
                        Severity: Major
                        Found in internal/constraints/operator_num.go and 4 other locations - About 30 mins to fix
                        internal/constraints/operator_num.go on lines 9..13
                        internal/constraints/operator_num.go on lines 15..19
                        internal/constraints/operator_num.go on lines 27..31
                        internal/constraints/operator_num.go on lines 33..37

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

                        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 5 locations. Consider refactoring.
                        Open

                        func operatorNumGt(ctx *context.Context, constraint api.Constraint) (bool, error) {
                            return operatorNum(ctx, constraint, func(context *big.Float, constraint *big.Float) bool {
                                return context.Cmp(constraint) > 0
                            })
                        }
                        Severity: Major
                        Found in internal/constraints/operator_num.go and 4 other locations - About 30 mins to fix
                        internal/constraints/operator_num.go on lines 9..13
                        internal/constraints/operator_num.go on lines 15..19
                        internal/constraints/operator_num.go on lines 21..25
                        internal/constraints/operator_num.go on lines 33..37

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

                        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 5 locations. Consider refactoring.
                        Open

                        func operatorNumGte(ctx *context.Context, constraint api.Constraint) (bool, error) {
                            return operatorNum(ctx, constraint, func(context *big.Float, constraint *big.Float) bool {
                                return context.Cmp(constraint) >= 0
                            })
                        }
                        Severity: Major
                        Found in internal/constraints/operator_num.go and 4 other locations - About 30 mins to fix
                        internal/constraints/operator_num.go on lines 9..13
                        internal/constraints/operator_num.go on lines 15..19
                        internal/constraints/operator_num.go on lines 21..25
                        internal/constraints/operator_num.go on lines 27..31

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

                        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 5 locations. Consider refactoring.
                        Open

                        func operatorNumLt(ctx *context.Context, constraint api.Constraint) (bool, error) {
                            return operatorNum(ctx, constraint, func(context *big.Float, constraint *big.Float) bool {
                                return context.Cmp(constraint) < 0
                            })
                        }
                        Severity: Major
                        Found in internal/constraints/operator_num.go and 4 other locations - About 30 mins to fix
                        internal/constraints/operator_num.go on lines 9..13
                        internal/constraints/operator_num.go on lines 21..25
                        internal/constraints/operator_num.go on lines 27..31
                        internal/constraints/operator_num.go on lines 33..37

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

                        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

                        Method Client.sync has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func (uc *Client) sync() {
                            for {
                                select {
                                case e := <-uc.errors:
                                    if uc.errorListener != nil {
                        Severity: Minor
                        Found in client.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