getwtxt/getwtxt

View on GitHub

Showing 11 of 13 total issues

Function apiEndpointHandler has 56 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func apiEndpointHandler(w http.ResponseWriter, r *http.Request) {
    errLog("Error when parsing query values: ", r.ParseForm())

    if r.FormValue("q") != "" || r.FormValue("url") != "" {
        err := apiEndpointQuery(w, r)
Severity: Minor
Found in svc/handlers.go - About 1 hr to fix

Function ParseRegistryTwtxt has 54 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func ParseRegistryTwtxt(twtxt []byte) ([]*User, error) {
    var erz []byte
    if len(twtxt) == 0 {
        return nil, fmt.Errorf("received no data")
    }
Severity: Minor
Found in registry/fetch.go - About 1 hr to fix

Method Registry.UpdateUser has 7 return statements (exceeds 4 allowed).
Open

func (registry *Registry) UpdateUser(urlKey string) error {
    if urlKey == "" || !strings.HasPrefix(urlKey, "http") {
        return fmt.Errorf("invalid URL: %v", urlKey)
    }

Severity: Major
Found in registry/user.go - About 45 mins to fix

Function GetTwtxt has 7 return statements (exceeds 4 allowed).
Open

func GetTwtxt(urlKey string, client *http.Client) ([]byte, bool, error) {
    if !strings.HasPrefix(urlKey, "http://") && !strings.HasPrefix(urlKey, "https://") {
        return nil, false, fmt.Errorf("invalid URL: %v", urlKey)
    }

Severity: Major
Found in registry/fetch.go - About 45 mins to fix

Method Registry.CrawlRemoteRegistry has 5 return statements (exceeds 4 allowed).
Open

func (registry *Registry) CrawlRemoteRegistry(urlKey string) error {
    if urlKey == "" || !strings.HasPrefix(urlKey, "http") {
        return fmt.Errorf("invalid URL: %v", urlKey)
    }

Severity: Major
Found in registry/user.go - About 35 mins to fix

Method Registry.DiffTwtxt has 5 return statements (exceeds 4 allowed).
Open

func (registry *Registry) DiffTwtxt(urlKey string) (bool, error) {
    if !strings.HasPrefix(urlKey, "http://") && !strings.HasPrefix(urlKey, "https://") {
        return false, fmt.Errorf("invalid URL: %v", urlKey)
    }

Severity: Major
Found in registry/fetch.go - About 35 mins to fix

Method Registry.AddUser has 5 return statements (exceeds 4 allowed).
Open

func (registry *Registry) AddUser(nickname, urlKey string, ipAddress net.IP, statuses TimeMap) error {

    if registry == nil {
        return fmt.Errorf("can't add user to uninitialized registry")

Severity: Major
Found in registry/user.go - About 35 mins to fix

Method Registry.DelUser has 5 return statements (exceeds 4 allowed).
Open

func (registry *Registry) DelUser(urlKey string) error {

    if registry == nil {
        return fmt.Errorf("can't delete user from empty registry")

Severity: Major
Found in registry/user.go - About 35 mins to fix

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

func handleUserDelete(w http.ResponseWriter, r *http.Request) {
    pass := r.Header.Get("X-Auth")
    if pass == "" {
        errHTTP(w, r, errors.New("unauthorized"), http.StatusUnauthorized)
        return
Severity: Major
Found in svc/handlers.go - About 35 mins to fix

Function ParseUserTwtxt has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
Open

func ParseUserTwtxt(twtxt []byte, nickname, urlKey string) (TimeMap, error) {
    var erz []byte
    if len(twtxt) == 0 {
        return nil, fmt.Errorf("no data to parse in twtxt file")
    }
Severity: Minor
Found in registry/fetch.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

Function ParseRegistryTwtxt has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
Open

func ParseRegistryTwtxt(twtxt []byte) ([]*User, error) {
    var erz []byte
    if len(twtxt) == 0 {
        return nil, fmt.Errorf("received no data")
    }
Severity: Minor
Found in registry/fetch.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