dstpierre/gosaas

View on GitHub

Showing 29 of 29 total issues

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

func RateLimiter(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        var keys Auth

        ctx := r.Context()
Severity: Major
Found in ratelimiter.go and 1 other location - About 4 hrs to fix
throttler.go on lines 15..56

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

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 Throttler(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        var keys Auth

        ctx := r.Context()
Severity: Major
Found in throttler.go and 1 other location - About 4 hrs to fix
ratelimiter.go on lines 16..57

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

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

File billing.go has 571 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package gosaas

import (
    "fmt"
    "log"
Severity: Minor
Found in billing.go - About 3 hrs to fix

    Method Billing.changePlan has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
    Open

    func (b Billing) changePlan(w http.ResponseWriter, r *http.Request) {
        ctx := r.Context()
        keys := ctx.Value(ContextAuth).(Auth)
        db := ctx.Value(ContextDatabase).(*data.DB)
    
    
    Severity: Minor
    Found in billing.go - About 2 hrs 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

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

    func (wh *Webhook) subscribe(w http.ResponseWriter, r *http.Request) {
        ctx := r.Context()
        keys := ctx.Value(ContextAuth).(Auth)
        db := ctx.Value(ContextDatabase).(*data.DB)
    
    
    Severity: Major
    Found in webhook.go and 1 other location - About 2 hrs to fix
    webhook.go on lines 151..167

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

    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 (wh *Webhook) delete(w http.ResponseWriter, r *http.Request) {
        ctx := r.Context()
        keys := ctx.Value(ContextAuth).(Auth)
        db := ctx.Value(ContextDatabase).(*data.DB)
    
    
    Severity: Major
    Found in webhook.go and 1 other location - About 2 hrs to fix
    webhook.go on lines 115..131

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

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

    func (b Billing) userRoleChanged(db data.DB, accountID int64, oldRole, newRole model.Roles) (paid bool, err error) {
        acct, err := db.Users.GetDetail(accountID)
        if err != nil {
            return false, err
        }
    Severity: Minor
    Found in billing.go - About 2 hrs 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 Billing.changePlan has 78 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (b Billing) changePlan(w http.ResponseWriter, r *http.Request) {
        ctx := r.Context()
        keys := ctx.Value(ContextAuth).(Auth)
        db := ctx.Value(ContextDatabase).(*data.DB)
    
    
    Severity: Major
    Found in billing.go - About 2 hrs to fix

      Function stripHTML has 58 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func stripHTML(s string) string {
          output := ""
      
          // if we have a full html page we only need the body
          startBody := strings.Index(s, "<body")
      Severity: Minor
      Found in queue/email/amazonses.go - About 1 hr to fix

        Method Billing.Convert has 58 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (b Billing) Convert(bc BillingNewCustomer) error {
            acct, err := b.DB.Users.GetDetail(bc.AccountID)
            if err != nil {
                return fmt.Errorf("unable to get the account for this account ID: %d -> %v", bc.AccountID, err)
            }
        Severity: Minor
        Found in billing.go - About 1 hr to fix

          Method Billing.Start has 55 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (b Billing) Start(bc BillingNewCustomer) error {
              p := &stripe.CustomerParams{Email: stripe.String(bc.Email)}
              p.SetSource(bc.StripeToken)
          
              c, err := customer.New(p)
          Severity: Minor
          Found in billing.go - About 1 hr to fix

            Method Billing.Overview has 53 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (b Billing) Overview(accountID int64) (*BillingOverview, error) {
                // this struct will be returned should we be a paid customer or not
                ov := &BillingOverview{}
            
                // Get the current account
            Severity: Minor
            Found in billing.go - About 1 hr to fix

              Method User.create has 52 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (u User) create(w http.ResponseWriter, r *http.Request) {
                  ctx := r.Context()
                  db := ctx.Value(ContextDatabase).(*data.DB)
                  isJSON := ctx.Value(ContextContentIsJSON).(bool)
              
              
              Severity: Minor
              Found in user.go - About 1 hr to fix

                Function extractKeyFromRequest has 8 return statements (exceeds 4 allowed).
                Open

                func extractKeyFromRequest(r *http.Request) (key string, pat bool, err error) {
                    // first let's look if the X-API-KEY is present in the HTTP header
                    key = r.Header.Get("X-API-KEY")
                    if len(key) > 0 {
                        return
                Severity: Major
                Found in auth.go - About 50 mins to fix

                  Method Billing.userRoleChanged has 7 return statements (exceeds 4 allowed).
                  Open

                  func (b Billing) userRoleChanged(db data.DB, accountID int64, oldRole, newRole model.Roles) (paid bool, err error) {
                      acct, err := db.Users.GetDetail(accountID)
                      if err != nil {
                          return false, err
                      }
                  Severity: Major
                  Found in billing.go - About 45 mins to fix

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

                    func (wh *Webhook) list(w http.ResponseWriter, r *http.Request) {
                        ctx := r.Context()
                        keys := ctx.Value(ContextAuth).(Auth)
                        db := ctx.Value(ContextDatabase).(*data.DB)
                    
                    
                    Severity: Minor
                    Found in webhook.go and 1 other location - About 45 mins to fix
                    user.go on lines 182..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 115.

                    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 (u User) profile(w http.ResponseWriter, r *http.Request) {
                        ctx := r.Context()
                        keys := ctx.Value(ContextAuth).(Auth)
                        db := ctx.Value(ContextDatabase).(*data.DB)
                    
                    
                    Severity: Minor
                    Found in user.go and 1 other location - About 45 mins to fix
                    webhook.go on lines 133..144

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

                    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 post has 6 return statements (exceeds 4 allowed).
                    Open

                    func post(url string, data interface{}, result interface{}, headers map[string]string) error {
                        b, err := json.Marshal(data)
                        if err != nil {
                            return err
                        }
                    Severity: Major
                    Found in webhook.go - About 40 mins to fix

                      Method Billing.Convert has 6 return statements (exceeds 4 allowed).
                      Open

                      func (b Billing) Convert(bc BillingNewCustomer) error {
                          acct, err := b.DB.Users.GetDetail(bc.AccountID)
                          if err != nil {
                              return fmt.Errorf("unable to get the account for this account ID: %d -> %v", bc.AccountID, err)
                          }
                      Severity: Major
                      Found in billing.go - About 40 mins to fix

                        Method Billing.changePlan has 6 return statements (exceeds 4 allowed).
                        Open

                        func (b Billing) changePlan(w http.ResponseWriter, r *http.Request) {
                            ctx := r.Context()
                            keys := ctx.Value(ContextAuth).(Auth)
                            db := ctx.Value(ContextDatabase).(*data.DB)
                        
                        
                        Severity: Major
                        Found in billing.go - About 40 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language