dstpierre/gosaas

View on GitHub

Showing 21 of 29 total issues

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

    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

                    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

                          Method Billing.Start has 6 return statements (exceeds 4 allowed).
                          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: Major
                          Found in billing.go - About 40 mins to fix

                            Method Billing.Overview has 5 return statements (exceeds 4 allowed).
                            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: Major
                            Found in billing.go - About 35 mins to fix

                              Function increaseThrottle has 5 return statements (exceeds 4 allowed).
                              Open

                              func increaseThrottle(key string, expire time.Duration) (int64, error) {
                                  i, err := rc.Incr(key).Result()
                                  if err != nil {
                                      return 0, err
                                  }
                              Severity: Major
                              Found in cache/throttling.go - About 35 mins to fix

                                Function Authenticator has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                Open

                                func Authenticator(next http.Handler) http.Handler {
                                    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                                        ctx := r.Context()
                                        mr := ctx.Value(ContextMinimumRole).(model.Roles)
                                
                                
                                Severity: Minor
                                Found in auth.go - About 35 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 setupCron has 5 return statements (exceeds 4 allowed).
                                Open

                                func setupCron() {
                                    if _, err := os.Stat("tasks.cron"); os.IsNotExist(err) {
                                        log.Println("no tasks.cron file found, skipping scheduler setup")
                                        return
                                    }
                                Severity: Major
                                Found in queue/queue.go - About 35 mins to fix

                                  Method Users.GetDetail has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (u *Users) GetDetail(id int64) (*model.Account, error) {
                                      account := &model.Account{}
                                      row := u.DB.QueryRow("SELECT * FROM gosaas_accounts WHERE id = $1", id)
                                      err := row.Scan(&account.ID,
                                          &account.Email,
                                  Severity: Major
                                  Found in data/postgres/users.go - About 35 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language