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"
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)
- Read upRead up
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
}
- Read upRead up
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)
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")
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)
}
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)
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
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)
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
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
}
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
}
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)
}
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)
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)
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
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
}
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)
- Read upRead up
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
}
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,