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()
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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()
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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
}
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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)